How to Change SSH Port in Ubuntu

To change the port for SSH service in Ubuntu. We just have to change the port number in our SSH configuration file.


  1. The SSH configuration file is located at /etc/ssh/sshd_config.

  2. To open the file in edit mode, execute the following command. But make sure you have sudo privileges or you are executing command as a root user.

  3. sudo nano /etc/ssh/sshd_config

  4. In the upper part of the file, you will see the current port number.Here, we need to change the current port number and set the desired port number.the updated line should look like this.

  5. Port (new port number)

  6. Once done, press CTRL+X followed by Y followed by Enter to save the file. Now, execute the following command to restart the SSH service. It is required to update configuration and make SSH listen on the new port.

  7. sudo service ssh restart

  8. Note that if you are using any kind of firewall, allow incoming connections on your desired SSH port before disconnecting with the server.


Now you can connect to your server using SSH on the new port.



這章程是否對您有幫助?

mood_bad 不喜歡 0
mood 喜歡 0
visibility 查看: 4005