Change Default SSH Port to Custom Port
Many time to secure our Linux server, we have to change the Default SSH port to some Custom port. Which is also a good practice to secure the servers.
Today we will learn, how to change the Default SSH port (22 port) to your Custom port.
To change the SSH port, please follow the below steps:
- Connect to your Linux server via SSH
- Switch to the root user using sudo su.
- Open sshd_config file:
1vi /etc/ssh/sshd_config
- Search the below line:
1# Port 22
- Remove # from the front and change 22 to your desired port number.
- lastly, Restart the sshd service by running the following command:
1service sshd restart
Note: Please check if firewall is ON or not. If its ON, then allow your Custom port also in firewall OR Disable the firewall.
Troubleshoot:
If you SSH service failed, while restarting the service.
Please revert back the changes then check if SELinux is enabled.
If enabled, Disable the SELinux using below steps:
- Open SELinux configuration and edit the file:
1vim /etc/sysconfig/selinux
- Change “SELINUX=enforcing” to “SELINUX=disabled”
- Save and exit the file. Then reboot the system.
1reboot