Log into your server as the root user.
Remove the number-sign (#) and change the value for the line.
For example, the default SSH port appears in a line like this:
#Port 22
To change the SSH port to 123, you will need to make the line appear like this:
Port 123
Update IPTables and Firewall
Any changes will also change your server's iptables and may overwrite any manual changes made directly to the iptables file itself.
After you are finished configuring SSH, you will need to add the port to iptables as well as your installed firewall.
To update iptables, please enter the following in SSH:
iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 123 -j ACCEPT
When using the command above, be sure to substitute 123 with the actual port number you are adding.
Reset SSH Daemon
After making the necessary changes to iptables and your computer's firewall, you will need to restart the SSH daemon. You can do it by entering this command:
/etc/init.d/sshd restart
Log out of your server and log in again using the proper user, IP address and port number you specified in sshd_config.