Want to change the ssh port for ssh? Here is a good tutorial.
(Note: If you are making these changes – ssh to the server and keep the terminal open as you make the changes. Test with a new terminal. This way if something is amiss – you are not locked out.)
Edit /etc/ssh/sshd_config, enter:
# vi /etc/ssh/sshd_config
The strategy used for options in the default sshd_config shipped with OpenSSH is to specify options with their default value where possible, but leave them commented. Uncommented options change a default value.
Uncomment the following and edit to set the port to 10221:
Note: If you have multiple IP address on the server, add you IP addresses.
ListenAddress as follows :
## bind sshd to two ip address on a non-standard port ## ListenAddress 192.168.1.5:10221 ListenAddress 220.127.116.11:10221
Save and close the file.
Before you restart or reload sshd server. You need to update SELinux configuration or Firewall settings (iptables).
You also need to update firewall settings so that users can login using TCP # 10221. Edit,
/etc/sysconfig/iptables and open sshd port 10221: # vi /etc/sysconfig/iptables
Edit/append as follows:
## delete or comment out port 22 line ## ## -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT ## open port 22 -A INPUT -m state --state NEW -m tcp -p tcp --dport 10221 -j ACCEPT
Save and close the file. If you are using IPv6, edit /etc/sysconfig/ip6tables file too. Temporally, stop the firewall so that you will not loose the connectivity to the server:
# service iptables stop # service ip6tables stop
Restart sshd on a CentOS
# service sshd restart
Verify new port settings with the following netstat command:
# netstat -tulpn | grep sshd
Finally, start the firewall:
# service iptables start ## IPv6 ## # service ip6tables start
Now, login with a different terminal to check the settings.