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
1 |
vi /etc/ssh/sshd_config |
In the file, find the line
1 |
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
1 |
systemctl restart ssh |
On RHEL-based Linux (AlmaLinux, RockeyLinux, Oracle Linux, CentOS)
1 |
systemctl restart sshd |
If you have a firewall, make sure you open the new port in the firewall.
See ssh