Changing the default SSH port

1 min read

To change the default SSH port, you need to edit the SSH configuration file located at /etc/ssh/sshd_config:

  • Open a terminal on the server and execute the command sudo nano /etc/ssh/sshd_config to open the file in the Nano text editor (or any other text editor you prefer).
  • Find the line with the text #Port 22, uncomment it (remove the '#' at the beginning of the line), and replace 22 with your desired port number (e.g., 2222). If such a line doesn't exist, add a new line Port 2222 (or another port number of your choice).
  • Save the changes to the file by pressing Ctrl+O and then close the editor by pressing Ctrl+X.
  • Restart the SSH service using the command sudo systemctl restart sshd to apply the changes.

Now you can connect to your server using the new SSH port by specifying the new port number with the -p parameter during the connection. For example: ssh user@server_ip -p 2222.

Didn’t find the answer?Contact support — we’ll help you sort it out.
Open a ticket →