How to configure multiple instances of sshd in RHEL 5 or 6?
Environment
- Red Hat Enterprise Linux (RHEL) 5
- Red Hat Enterprise Linux 6
openssh-server
Issue
How to configure multiple instances of sshd
in Red Hat Enterprise Linux 5 or 6? Is that supported?
Resolution
This resolution applies to Red Hat Enterprise Linux 5 or 6 only. If you want to run multiple instances of sshd
on RHEL 7, please see another solution describing the same for RHEL 7.
Disclaimer: Writing init script for second instance is out of scope of work. Given below is just an example.
Running multiple instances of sshd on RHEL5/6 is supported. Follow the steps below to configure a second instance of the sshd
daemon.
-
Make a copy of the
sshd_config
file (to be used by the second daemon)# cp /etc/ssh/sshd_config /etc/ssh/sshd_config-second
-
Edit the
/etc/ssh/sshd_config-second
file to assign a different port number and pid file. Make sure this port is not in use by any other servicePort 5222 PidFile /var/run/sshd-second.pid
-
Make a symlink to the
sshd
binary (see RHBZ #826720) and make a copy of thesshd
init script# ln -s /usr/sbin/sshd /usr/sbin/sshd-second # cp /etc/rc.d/init.d/sshd /etc/rc.d/init.d/sshd-second
-
Find the lines below in the
/etc/rc.d/init.d/sshd-second
file and make the changes accordingly.# config: /etc/ssh/sshd_config-second # pidfile: /var/run/sshd-second.pid [ -f /etc/sysconfig/sshd-second ] && . /etc/sysconfig/sshd-second prog="sshd-second" SSHD=/usr/sbin/sshd-second PID_FILE=/var/run/sshd-second.pid [ -f /etc/ssh/sshd_config-second ] || exit 6
-
Create the
/etc/sysconfig/sshd-second
file with the following contents:OPTIONS="-f /etc/ssh/sshd_config-second"
-
Create a separate PAM configuration file for the new
sshd-second
service.# cp /etc/pam.d/sshd /etc/pam.d/sshd-second
-
If SELinux is enabled, on RHEL6 system, set the security context for the
sshd-second
service# semanage fcontext -a -e /etc/init.d/sshd /etc/init.d/sshd-second # semanage fcontext -a -e /usr/sbin/sshd /usr/sbin/sshd-second # semanage fcontext -a -e /etc/ssh/sshd_config /etc/ssh/sshd_config-second # restorecon -v /etc/init.d/sshd-second /usr/sbin/sshd-second /etc/ssh/sshd_config-second
8a. If SELinux is enabled, on RHEL5 system, instead of semanage
use chcon
command to change the context:
~~~
# chcon --reference=/etc/init.d/sshd /etc/init.d/sshd-second
# chcon --reference=/usr/sbin/sshd /usr/sbin/sshd-second
# chcon --reference=/etc/ssh/sshd_config /etc/ssh/sshd_config-second
~~~
8b. If you need to use semanage
on a RHEL5 system you can use the following commands to set the context:
~~~
# semanage fcontext -a -t initrc_exec_t /etc/init.d/sshd-second
# semanage fcontext -a -t sshd_exec_t /usr/sbin/sshd-second
# semanage fcontext -a -t etc_t /etc/ssh/sshd_config-second
# restorecon -v /etc/init.d/sshd-second /usr/sbin/sshd-second /etc/ssh/sshd_config-second
~~~
-
If the iptables firewall is enabled, insert a rule in the
INPUT
chain to open the port for thesshd-second
service. In this example, the rule should be inserted at slot 9, before thereject-with icmp-host-prohibited
line. (Thesystem-config-firewall
GUI tool can make this step easier on RHEL 6.)# iptables -L --line-numbers Chain INPUT (policy ACCEPT) num target prot opt source destination ... 8 ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ssh 9 REJECT all -- anywhere anywhere reject-with icmp-host-prohibited ... # iptables -I INPUT 9 -m state --state NEW -m tcp -p tcp --dport 5222 -j ACCEPT
-
Restart the
sshd
service and the newly createdsshd-second
service, and usechkconfig
to start thesshd-second
service on reboot.# service sshd restart # service sshd-second start # chkconfig --add sshd-second
-
On the client, specify the port number with the
-p
option to connect to thesshd-second
daemon# ssh user1@ipaddress -p 5222
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.
Comments