In this article, we want to teach you how to change the SSH port in Ubuntu. The SSH protocol (also known as Secure Shell) is a method for securing remote login from one computer to another. It provides several alternative options for strong authentication, and it protects the communication’s security and integrity with strong encryption. It is a secure alternative to the non-protected login protocols (such as telnet, rlogin) and insecure file transfer methods (such as FTP).
The default port of the SSH service is 22, it’s better to change the default SSH port to increase the security of your server.
Steps To change the SSH port in Ubuntu
It is a very easy task to change the port for the SSH service. To do this, you can follow the steps below.
Step 1 – Check Current Ubuntu SSH Configuration
In Ubuntu 20 or other versions of the Ubuntu ecosystem you can check the current configuration with the following command:
grep -i port /etc/ssh/sshd_config
Step 2 – Change SSH Port Ubuntu
If you want to change the default SSH port, use the following command to open the SSH config file:
sudo vi /etc/ssh/sshd_config
After entering the above command, we will see the contents of the sshd_config file.
Next, you need to change the specified number 22 to another value (for example port 3823). We also need to remove the # character from the beginning of this line to use this line as an active operating command on the server.
When you are done, save and close the file.
Restart the SSH server with the following command to apply the changes:
systemctl restart sshd
After that, run the netstat command and make sure that the ssh daemon now listens on the new ssh port:
netstat -pnltu | grep ssh
You’ll see this output if you configure the SSH port correctly:
root@ubuntu:~# netstat -pnltu | grep ssh tcp 0 0 0.0.0.0:3823 0.0.0.0:* LISTEN 18321/sshd tcp6 0 0 :::3823 :::* LISTEN 18321/sshd
Step 3 – Allow new SSH port on Ubuntu UFW firewall
Here you can allow the new port through the firewall. To do this, run the following commands:
# sudo ufw allow 3823/tcp # sudo ufw reload
Now you can exit and sign in using a new port with the following command:
ssh –p 3823 user@ip-address
At this point, You have learned to increase your security logins by changing the SSH port on the Ubuntu server. You can easily do it by editing the SSH config file, and changing the default port number, and allowing it through your Ubuntu server’s firewall.
Hope you enjoy it. Stay tuned for more articles.
You may like these articles: