How to change the SSH server 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.

Changing the SSH port number

To change the port for the SSH server, follow these steps:

  1. Log in to the server as root using SSH.
  2. Open the /etc/ssh/sshd_config file in your preferred text editor (nano, vi, etc.).
  3. Locate the following line:
    Port 7822
    Remember that for security reasons, A2 Hosting uses port 7822 for SSH connections instead of the default port 22.
  4. Change 7822 to the new port number that you want to use.
  5. Save the changes to the /etc/ssh/sshd_config file, and then exit the text editor.
  6. Restart the SSH service using the appropriate command for your Linux distribution:

    • For AlmaLinux and Fedora, type:
      service sshd restart
      
    • For Debian and Ubuntu, type:

      service ssh restart
      
  7. 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.

Did you find this article helpful? Then you'll love our support. Experience the A2 Hosting difference today and get a pre-secured, pre-optimized website. Check out our web hosting plans today.

We use cookies to personalize the website for you and to analyze the use of our website. You consent to this by clicking on "I consent" or by continuing your use of this website. Further information about cookies can be found in our Privacy Policy.