Hostwinds Tutorials

Search results for:

Table of Contents

How To Change Your SSH Port

How To Change Your SSH Port

Tags: VPS 

How To Change Your SSH Port

How To Change Your SSH Port

Changing your SSH port can be a crucial step when securing your VPS against potential malicious activity. This article will cover the process of changing your server's SSH port. You'll need to be logged into your server via SSH. If you're not sure how to access your server via SSH, please refer to our guide: Connecting to Your Server via SSH.

This article requires the editing of key SSH configuration files. You can use any text editor that you'd like, however. For this article, we will be using the Linux text editor nano. Once you're are ready to proceed, please refer to the following steps.

Step 1: Change your directory to /etc/ssh/  via the following command

cd /etc/ssh/

Step 2: Here, you'll want to make a backup of your current sshd_config. To do this, run the following command

cp sshd_config sshd_config.bak

Step 3: You'll now need to edit the sshd_config file via the following command

nano sshd_config

Step 4: In nano, search for the word "port" by pressing ctrl+w, then typing in port and pressing enter

Step 5: Once you locate the port setting, you can delete the # symbol to uncomment the line

Step 6: Change the port number, which should be 22, to any port you wish under 65535

Step 7: It is advised not to use the following ports as they are generally in use

  1. 25
  2. 110
  3. 443
  4. 495
  5. 21
  6. 80
  7. 2083
  8. 2082
  9. 2086
  10. 2087
  11. 2096
  12. 9876

You can always cat /etc/services  to find which port numbers are configured on your server

Step 8: Finally restart the SSH service with the following command

service sshd restart

Written by Michael Brower  /  June 23, 2017