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 files.


  1. The SSH configuration files is located at /etc/ssh/sshd_config and /etc/ssh/ssh_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.

  7. Also, make the same changes on /etc/ssh/ssh_config

  8. Now, execute the following command to restart the SSH service. It is required to update configuration and make SSH listen on the new port.

  9. sudo service ssh restart

  10. 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.



Was this article helpful?

mood_bad Dislike 0
mood Like 0
visibility Views: 153