SSH or secure shell is a network protocol. We use it to connect and access remote servers. We can change the default SSH port to enforce the security against the brute force attacks on your servers.
Please refer to the following steps to change the default SSH port on CentOS.
- Login to your CentOS server using root or sudo user.
- Open the file sshd_config at the path /etc/ssh using the below command in your favorite editor.
- Uncomment the line mentioned port 22 and change it to your required port. Here we have changed it to port 8756.
- Save and exit from the sshd_config file.
- If you have installed the firewall on your server, please ensure that you add the new RDP port. Else, it will not allow connecting your system using ssh.
Allow SSH port on Firewalld
firewall-cmd --zone=public --add-port=8756/tcp --permanent
firewall-cmd --reload
Allow SSH port on Iptables
iptables -A INPUT -p tcp -m tcp --dport 8756 -j ACCEPT
systemctl restart iptables
- Run the below command to restart the ssh service.
systemctl restart sshd