SSH Port | How To Change Server's SSH Port Number?
This article describes how to change the SSH port number for a server. You may want to do this for security reasons, for example, or if you use a third-party service that requires a specific SSH port number.
The following procedure only applies to unmanaged accounts. Shared and reseller hosting accounts do not have root access to the server and cannot change the SSH port number.
Open the /etc/ssh/sshd_config file in your preferred text editor (nano, vi, etc.).
Locate the following line:
Remember that for security reasons, A2 Hosting uses port 7822 for SSH connections instead of the default port 22.
Change 7822 to the new port number that you want to use.
Save the changes to the /etc/ssh/sshd_config file, and then exit the text editor.
Restart the SSH service using the appropriate command for your Linux distribution:
For CentOS and Fedora, type:
service sshd restart
For Debian and Ubuntu, type:
service ssh restart
While still logged in as root, in a new terminal window try to log in using the new SSH port number. If the login fails, check your settings. Do not exit your open root session until you are able to log in using the new configuration.
If you have a firewall configured for your server, you must also update the firewall rules to allow access on the new SSH port:
For information about how to update a firewall using iptables, please see this article.
For information about how to update a firewall using Advanced Policy Firewall (APF), please see this article.