• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

How to run ssh on multiple ports

by admin

Question: How to confgure ssh to run on 2 ports i.e. 22 and 2222.

There may be requirements as such above in some environments to run ssh on multiple ports. Well this can be achieved by modifying the /etc/ssh/sshd_config configuration file.

The stpes are outlined as below:

1. Edit the sshd configuration file /etc/ssh/sshd_config

# vi /etc/ssh/sshd_config

2. The Port directive in this file indicates on which port sshd should listen on. The default port here should be mentioned as 22. You can add multiple Port directives here to enable sshd to listen on multiple ports. For example:

Port 22
Port 2222

3. Save the file and take restart of the sshd service for the changes to take effect.

# service sshd restart
Stopping sshd                                       [  OK  ]
Starting sshd                                       [  OK  ]
Note: You may want to check if the syntax of the file /etc/ssh/sshd_config is correct before restarting the sshd service. You can use the command “sshd -t” to verify the syntax.

4. Verify the new ports are in LISTEN mode in the “ss” command:

# ss -anp | grep LISTEN | grep sshd

Troubleshooting

– In case the new port is not in LISTEN mode, you may check the /var/log/secure logs on the server for any errors.
– Also check if SELinux is not allowing the non-standard port. If required you may have to either disable SELinux or allow the new port in SELinux.

Bind to port 22 on 0.0.0.0 failed: address already in use – error while starting sshd service CentOS/RHEL
“error: Bind to port 2222 on 0.0.0.0 failed: Permission denied” – error while starting sshd service on CentOS/RHEL

Filed Under: CentOS/RHEL, CentOS/RHEL 5, CentOS/RHEL 6, Linux

Some more articles you might also be interested in …

  1. Linux OS Service ‘microcode_ctl’
  2. How to Enable Debug Mode for Chronyd Service in CentOS/RHEL 8
  3. How to troubleshoot iSCSI issues in CentOS / RHEL 6,7
  4. fscrypt: command not found
  5. How to add Source, Services and Ports to Firewall Zone in CentOS/RHEL 7 and 8
  6. RHEL / CentOS : How to shrink LVM volume
  7. How to Move Swap From Disk Partition to LVM Volume in Linux
  8. gcov Command Examples in Linux
  9. service Command Examples in Linux
  10. Linux OS service ‘portmap’

You May Also Like

Primary Sidebar

Recent Posts

  • powertop Command Examples in Linux
  • powertop: command not found
  • powerstat: command not found
  • powerstat Command Examples in Linux

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright