This step-by-step guide explains how to change the default SSH port (22) on your Linux machine.
Here’s a useful tip for people that access their computer or server over the Internet using SSH. Change your SSH port from the default port 22 to something else. Although this is not a foolproof hack to secure your server, it can help. Let’s look at you this would be done on an Ubuntu machine. NOTE that this change should not be performed over a remote SSH connection, you might lose all contact with your server.
# netstat -tulpn
In the output you should see an entry for port 22. This is the SSH service.
# sudo vim /etc/ssh/sshd_config
At the beginning of the file you will a line that looks has Port 22 on it. Change the number 22 to something of your choice, for example, 678. Save the file and exit.
# sudo /etc/init.d/ssh restart
# ssh -p 678 user@servername.com
Little hacks like these go a long way to helping you secure your Linux box.