By default, port 22 is used to establish an SSH connection. This port is automatically configured during the installation of your operating system. 

To reduce the number of brute force attacks, you can configure another port for SSH access. 

Please Note

Before changing the port, make sure that the applications and services installed on the server can be configured without a default port. Otherwise, changing the default port may cause these applications and services to stop working.

To change the SSH port:

  • Log on to the server as an administrator.

  • Open the SSH configuration file sshd_config with the text editor vi:
    vi /etc/ssh/sshd_config

  • Search for the entry Port 22.

  • Replace port 22 with a port between 1024 and 65536

Please Note

Make sure that the selected port is not used for other services. You can do this by using the following port list provided by the Internet Assigned Numbers Authority (IANA):

https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xhtml

Alternatively, you can view the list of ports in the /etc/services file.

  • Save the file.

  • Restart the service.

    Ubuntu

    service ssh restart
    CentOS 7

    systemctl restart sshd
    To establish an SSH connection after this change, enter the following command:
    ssh root@IP_address_of_the_server -p NewPort

Was this answer helpful? 56651 Users Found This Useful (2231 Votes)