You can change the default SSH port for your Linux server as an added security measure.

Warning: Make sure the new SSH port does not conflict with any known or blocked ports.

To Change the SSH Port for your Redhat / CentOS Linux Server

  1. Connect to your linux server via SSH
  2. Switch to the root user
  3. Run the following command:
    nano /etc/ssh/sshd_config

    or

    vi /etc/ssh/sshd_config
  4.  Locate the following line:
    # Port 22
  5. Remove # and change 22 to your desired port number.
  6. Restart the sshd service by running the following command:
    service sshd restart

     

Troubleshooting:

In the event that you experience the following error when restarting the sshd service:

Job for sshd.service failed because the control process exited with error code. See "systemctl status sshd.service" and "journalctl -xe" for details.

Run the following command:

semanage port -a -t ssh_port_t -p tcp #PORTNUMBER

where #PORTNUMBER is the port set in the sshd_config

Now run:

service sshd restart

and you will see it is successful.