Changing the Default SSH Port

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

  • Linux, port22, ssh
  • 56651 Users Found This Useful
Was this answer helpful?

Related Articles

Step-by-Step Guide to Migrate Your WordPress Site to a New Host | Vcclhosting

Step-by-Step Guide to Migrate Your WordPress Site to a New Host Step 1: Back up your website...

How to Reset my cPanel Account Password?

If you can access your cPanel account, follow these steps to reset your password:1. Log into your...

How to update your cPanel Contact Information or receive a notification on reaching quota limit?

If you want to receive notification on reaching your disk quota, bandwidth usage limit, reaching...

How to Change cPanel Style/Theme?

Switching over to another cPanel theme with a different style is easy and there are two ways to...

How to Change Language of your cPanel?

cPanel supports a lot of languages, and if you want to change your cPanel language to your native...