Modifying your SSH port is an important step in securing your VPS or dedicated server from abusive activity. This article will go over the procedure of changing the servers SSH port. You’ll need to log into your server using SSH. If you’re not certain about the basic ssh commands then consult our guide on useful commands to manage your Server through SSH.
This article requires editing of the key SSH file configurations. You can use any text editor you like, but. In this case we’ll use nano, the Linux Nano text editor.
When you’re in a position to begin, be sure to follow the next steps.
Step 1: Change your directory to /etc/ssh/ via the below command
Step 2: Here, you need to make a backup of your current sshd_config for security side. To do this, run the below command
cp sshd_config sshd_config.bak
Step 3: You’ll now need to edit the sshd_config file using the below command
Step 4: In nano, search for the word “port” by using ctrl+w
Step 5: Once you able to 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 eg 1981
Step 7: It is advised not to use the below ports as they are generally in use for the different services
You can always use command cat /etc/services to find which port numbers are configured on your server
Step 8: Finally restart the SSH service with the following command and changes will get applied.
service sshd restart