How to change the SSH port for a Linux server

Secure Shell (SSH) allows HostPapa VPS users to log in and manage their server using a command line application, such as Terminal on Mac OS and Linux, or a third-party application like PuTTY on Windows.

SSH communications typically operate over port 22, but if you wish to tighten security, you could change the SSH port to an alternative. Use the following steps to change the SSH port for a Linux server.

Port 22

Log in to your VPS server using SSH, using Terminal or an alternative SSH command line app. You should log in with the root administrator. To read more about accessing your server via SSH, please read this article: How to connect to your server via Secure Shell (SSH).

SSH login

Once logged in, run the following command:

vi /etc/ssh/sshd_config

SSH Configuration file

The SSH configuration file will open. Locate the following line:

# Port 22

Port line

Type i to enter the vi text editor’s Insert mode. Delete the “#” and change the port number to an alternative. Press Escape to return to vi’s Command mode.

Type 😡 to save the file and quit the vi text editor.

Now run the following command to restart the SSH service on your server with the new port number.

service sshd restart

For further questions, or if you need help, please open a support ticket from your HostPapa Dashboard. Follow this link to learn how.

Was this article helpful?

[was-this-helpful]

Related Articles

Leave A Comment?