Steps for Linux 6 to modify the default ssh remote port number
- 2021-06-28 14:38:05
- OfStack
The default ssh remote port for linux is 22. Sometimes the default port is scanned or attacked by unintentional people. To make our system more secure, we need to modify the remote port number.
Operation steps:
1. Modify ssh_config Profile
vim /etc/ssh/sshd_config
2. Line #Port 22 found in configuration file (default port 22)
3. Modify the line to the port number you want
Port 222 (Note: Remove the # before)
4. [Optional] If you want to add a port number to coexist (port 22 and 222 are valid simultaneously)
Port 22 (Note: No #before)
Port 222 (Note: No # in front)
5. Restart sshd service after leaving
/etc/init.d/sshd restart
If you have a firewall set up, you need to add a new port rule
6. Edit iptables file
vim /etc/sysconfig/iptables
7. Add 222 Port Rule
-A INPUT -m state � state NEW -m tcp -p tcp � dport 222 -j ACCEPT
8. Save and restart iptables service after exit
service iptables restart
9. Test connection and finish work.
summary