How to Configure SSH to use a different Port on CentOS 7+

Configure SSH to use a different Port on CentOS 7

Step through this guide to learn how to configure SSH server to listen on a different port.

  1. Login to your server and open the OpenSSH server configuration file, /etc/ssh/sshd_config for editing.
    nano /etc/ssh/sshd_config
  2. Uncomment the line, # Port 22 and set it to a desired port. But as a safety measure, just in case things go south, configure sshd to listen on two ports, the default port and the desired port such that your config files have two lines like as shown below. Once you confirm that the new port works fine, remove the default port setting.
    Port 22
    Port 3456 <where 3456 is your preferred port>


    • Ensure that no other service is using the new port.
    • Replace the ports accordingly.
  3. If firewall is running, allow the new port on through it.
    firewall-cmd --add-port=3456/tcp --permanent
    firewall-cmd --reload
  4. Restart sshd service
    systemctl restart sshd
Published on: 7/30/20, 9:21 AM