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 ]
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.
“error: Bind to port 2222 on 0.0.0.0 failed: Permission denied” – error while starting sshd service on CentOS/RHEL