Change SSH Port CentOS

To change the SSH port on CentOS, you can follow these steps:

  1. Connect to the CentOS server using SSH.
  2. Open the SSH configuration file using a text editor like vi or nano. In most cases, the SSH configuration file can be found at /etc/ssh/sshd_config.
sudo vi /etc/ssh/sshd_config
  1. In the open configuration file, locate the “Port” line. Change it to the new port number you want. For example, change the port number to 2222.
Port 2222
  1. Save and close the file. In the vi editor, you can press the “Esc” key, then type “:wq”, and press the “Enter” key.
  2. Restart the SSH service to apply the new port configuration.
sudo systemctl restart sshd
  1. Make sure the firewall allows new ports to pass through. You can use the following command to add new ports to the firewall rules:
sudo firewall-cmd --zone=public --add-port=2222/tcp --permanent
sudo firewall-cmd --reload

You have now successfully changed the SSH port on the CentOS server to 2222. You can now connect to the server using the new port number. Remember to specify the new port number when connecting.

bannerAds