How to Change the SSH Port on Linux

linux ssh portchange ssh portsecure ssh connectionsshd_configssh security
Published·Modified·

What is the SSH Port?

In simple terms, the SSH port is the port used for remote connections to a Linux server. The default port is 22. However, if your server is still using the default SSH port, you should be cautious. Bots frequently scan ports and attempt brute-force attacks. If your password is also set too simply, your server may be compromised.

This article introduces how to change the SSH port on a Linux server. It is recommended to modify the default port 22 for login. If you have strict security requirements, you may also consider generating key files for login, though this article does not cover that in detail. Interested readers can search for relevant documentation online.

linux

How to Modify the SSH Port

Enter the following command to edit the configuration file:

vi /etc/ssh/sshd_config

Locate the line #Port 22. Remove the # symbol and change 22 to the port number you wish to set. Finally, save and exit the editor. Additionally, do not casually disclose the new port number to others.

vi_etc

port_22

Restart the SSH Service

Finally, enter the following command to restart the SSH service:

service sshd restart

On your next login, you will need to use the modified port. For example, if you changed the port to 2200, the login process will look like the screenshot below.

port22