How to modify the SSH server port number

September 19, 2023 / Tutorials

In this article, we will explain how to modify the SSH server port number.

SSH or Secure Shell, is used to secure connections with remote hosts on the default port number 22. However, for security reasons or to thwart potential brute force attacks, you may wish to alter this default port to a different one.

Follow these steps to change the SSH port number:

  1. Log into your root account.
  2. To  change the ssh port number, enter the following command:
    #vi /etc/ssh/sshd_config


  3. Now, as you can see, Port 22 is the current port number which we have disabled by adding # and Port 1927 is the new port number.
    Port Number
  4. After changing the SSH port number, you must execute the “systemctl restart sshd” command to ensure the changes take effect.
  5. To check or verfiy the sshd service status, use the following command line-
    systemctl status sshd
  6. Now, you need to allow port 1927 through your firewall. Run the following command-
    firewall-cmd --permanent --add-port=1927/tcp

  7. Verify the Firewalld status and you will observe that the Firewalld service has transitioned to an Active state, indicating it is currently running.

  8. Now, you can access your new server using the recently configured SSH port.

In this way, you can change or update you SSH server port number.

Spread the love