How to modify the SSH port

July 10, 2023 / Security and Backups

In this guide, we have explained how to modify the SSH port. Port 22 is used to obtain an SSH linking. Port 22 is automatically formed while installing operating system. To reduce the number of brute force attacks, you can form another port for SSH access.

Important note – Make sure that the apps and services installed on the server can be configured without a default port before making any change. Or else it may happen that the port will not support the working of the apps and services.

Follow the steps-

  1. Log on to the server as admin.
  2. With the help of text editor vi, open the SSH configuration file sshd_config-
    vi /etc/ssh/sshd_config
  3. Find the entry port-22.
  4. Now, you can replace port 22 with the new port. (Port 1024- 65536).
  5. Make note of one thing that the port you select is not in use of any other service. You can check by using the following link provided by the (IANA)-
    https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xhtml
  6. You can also view the list of the ports in the file-/etc/services
  7. “Save” the file.
  8. “Restart” the service as given below-
    1. For Ubuntu-
      service ssh restart
    2. For CentOS 7-
      systemctl restart sshd
    3. After changing the port to establish an SSH connection, execute the below command-
      ssh root@IP_address_of_the_server -p NewPort

In this manner, you can change SSH port. Hope you liked our article and that it was of great help to you.

For any extra assistance, get in touch with our support staff at WHUK.

Spread the love