How to change the remote port in CentOS 7?

To change the remote port on CentOS 7, you need to edit the SSH server configuration file and restart the SSH service. Here are some steps:

  1. Login to the CentOS 7 server as the root user.
  2. Open the SSH server configuration file /etc/ssh/sshd_config, and you can edit it using a text editor like vi or nano.
  3. Edit the sshd_config file with superuser privileges using the vi text editor.
  4. Locate the “#Port 22” line in the configuration file and either comment it out or delete it.
  5. Add a new port number below the line, for example, changing the port number to 2222:
  6. Port number 2222
  7. Save the file and exit the editor.
  8. Restart the SSH service to apply the changes.
  9. Restart the sshd service using systemctl command.

Now, you will be able to remotely log in to the CentOS 7 server using the modified port number through SSH. Make sure to open the new port in the firewall so that the SSH service can be accessed. If you are using a firewall management tool like firewalld, you can use the following command to open the new port:

sudo firewall-cmd --permanent --zone=public --add-port=2222/tcp
sudo firewall-cmd --reload

Please be aware that if your server is located in a restricted network environment, you may also need to configure port forwarding on network devices (such as routers or firewalls) to route external traffic to the modified port.

Leave a Reply 0

Your email address will not be published. Required fields are marked *