December 17, 2010

How to change the default ssh port

On Ubuntu, we can edit the '/etc/ssh/sshd_config' file to change the port our ssh server is listening on. You should find something similar to the following in this file.

Port 22

You can change this value to any integer between 1025 and 65536 (inclusive). You should pick a value that won't conflict with any other services. If you want to limit ssh access to specific users, then you can add the users to the 'AllowUsers' setting separated by spaces. Once you make the changes, you'll need to reload ssh to use the new configurations.

mike@shiner $ sudo /etc/init.d/ssh reload
[sudo] password for mike: 
 * Reloading OpenBSD Secure Shell server's configuration sshd
   ...done.

You should stay logged in until you can test the configuration by logging in from a different machine. If we changed the 'Port' value to 4200, then we can use the following command to specify port 4200 on the remote machine for ssh.

mike@primus $ ssh -p 4200 mike@shiner

No comments:

Post a Comment