CentOS Linux 5/6: Change OpenSSH Port Number

www.lau‮irutt‬.com
CentOS Linux 5/6: Change OpenSSH Port Number

To change the port number that OpenSSH listens on in CentOS Linux 5/6, you will need to edit the OpenSSH server configuration file.

  1. Open the /etc/ssh/sshd_config file in a text editor.
sudo nano /etc/ssh/sshd_config
  1. Locate the line that begins with Port and change the port number to the desired value. For example, to change the port to 2222:
Port 2222
  1. Save and close the sshd_config file.

  2. Restart the OpenSSH server to apply the changes:

sudo service sshd restart
  1. If you are using a firewall, you will need to allow incoming connections on the new port. For example, to allow incoming connections on port 2222 using firewalld:
sudo firewall-cmd --add-port=2222/tcp --permanent
sudo firewall-cmd --reload

After completing these steps, the OpenSSH server will listen on the new port number that you specified. You will need to specify the new port number when connecting to the server using an SSH client.

Note: It is generally a good idea to use a non-standard port number for SSH to reduce the risk of automated attacks. However, changing the port number will not provide much security on its own and should be used in combination with other security measures such as strong passwords and SSH key authentication.

Created Time:2017-10-16 14:38:40  Author:lautturi