How to Change the Default SSH Port in Ubuntu: A Step-by-Step Guide

fidilen
2 min readApr 14, 2023

--

Changing the default SSH port in Ubuntu is a great way to increase your server’s security. By changing the default port, it makes it harder for malicious users to access your server.

The SSH server on Ubuntu listen on TCP port 22 by default. It is highly recommended to alter the default port number for SSH, as soon as possible. This makes it more difficult for attackers to target port 22 and consequently increases security.

Steps

The process of changing the default SSH port is relatively simple and can be done in a few steps:

Open the /etc/ssh/sshd_config file using this command:

sudo nano /etc/ssh/sshd_config

Locate the line:

#Port 22

Remove the # and change the value 22 with an appropriate port number from 1024 to 65535.

Save the file: Ctrl + O > Enter > Ctrl + X

Finally, restart the SSH server:

systemctl restart sshd

Moving forward, if you want to connect to a server using SSH, you need to specify the port with the -p flag.

ssh -p port_number ip_address

Conclusion

In conclusion, changing the default SSH port in Ubuntu is a simple process that requires only a few steps. With these simple steps, you will be able to increase the security of your server.

Need Assistance?

Contact me via Discord or any socials.

--

--

fidilen
fidilen

Written by fidilen

0 Followers

Full Stack Developer · Bot Developer · Web Developer · API Developer · SQL Developer https://fidilen.com