How to change the SSH Port in Linux

By default SSH service runs on port 22. Running SSH service on port 22 is not secure as it can become an easy target for attackers who are scanning the network for open ports. By changing the default port, you can make it more difficult for attackers to find and exploit the SSH service.

To change SSH port, edit file

vi /etc/ssh/sshd_config

In the file, find the line

Port 22

Change 22 to whatever port number you want. It is better to use a higher port number so it will be difficult for hackers to find.

Restart SSH service

On Debian/Ubuntu

systemctl restart ssh

On RHEL-based Linux (AlmaLinux, RockeyLinux, Oracle Linux, CentOS)

systemctl restart sshd

If you have a firewall, make sure you open the new port in the firewall.

See ssh

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *