Change SSH Port in CentOS

To change the remote port on CentOS, follow these steps:

  1. Log in to the CentOS server and open the SSH configuration file. You can use the following command to open the configuration file:
sudo vi /etc/ssh/sshd_config
  1. In the open configuration file, locate the “Port” keyword and then change the port number after it to the new port number you want to use. For example, change the port number from the default 22 to 2222:
Port 2222
  1. Save the modifications and exit the editor, then restart the SSH service for the changes to take effect. You can use the following command to restart the SSH service:
sudo systemctl restart sshd
  1. If your CentOS server has firewall configuration, make sure to open the new port. You can use the following command to add the new port to the firewall configuration:
sudo firewall-cmd --zone=public --add-port=2222/tcp --permanent
sudo firewall-cmd --reload

You have successfully changed the remote port on the CentOS server. Remember to use the new port number (e.g. 2222) when connecting to the server.

bannerAds