Using multiple SSH daemons on one host

patvdv — Fri, 20/06/2008 - 22:01
Recently I ran into the situation where I needed to hook up 2 CentOS GNU/Linux servers to allow the transfer of a large data volume between the both of them. Both servers are internet facing systems and the obvious choice would have been to haul the data across via SCP (secure copy) using the public network interface. Unfortunately, all traffic originating from the public interface was being billed and the entire data transfer would have resulted in a rather hefty bill if I would have used the public internet as transport medium. An additional requirement stipulated that this kind of data transfer would need to happen on a regular basis which would make the use of CD/DVD's rather cumbersome. Since both boxes had a second NIC, the obvious choice was to connect them via a simple cross cable and to use a non-routable IP range for these NICs. Here is a simplified picture of the network setup:

-
eth0: public interface, wired to switch/router, internet facing (IP: 213.123.213.1 & 213.123.213.2)
-
eth1: private interface, wired via cross-cable to other server (IP: 10.10.0.1 & 10.10.0.2)
By default, the standard SSHD configuration on CentOS will cause the SSHD to listen on all available network interfaces. In my case that was on eth0 and eth1. So that is all that would have been required to make the secure copy work across the private network.
However, the big disadvantage of this approach is that applied security settings for the running SSH daemon are valid for both networks. Typically, I never allow password based authentication on a public server but rather use SSH private/public keys instead. Additionally, direct root logins are also never allowed. Having to deal with this elevated security turned out to be rather a nuisance because opening terminal sessions and copying files always would have to happen using SSH keys and non-root logins.
To reconcile security and operational requirements I decided to go for the following solution: to run 2 separate SSH daemons, one for each network interface. In my case I called the second SSH daemon serving the private NIC sshd-internal.
The rest of the topic describes the required configuration to get this up and running. All steps have to be replayed on both systems using the applicable IP addresses where necessary. Replace the IP addresses in the listings with IP addresses that are valid for your setup.
SSH daemon configuration
We start with creating a new sshd_config file in /etc/ssh:
# cd /etc/ssh # cp sshd_config sshd_config-internal
In the sshd_config-internal configuration file we can relax the security settings a bit and we change the ListenAddress directive so that the sshd-internal will only listen on the private network interface:
# diff sshd_config sshd_config-internal
57c57 < PasswordAuthentication no --- > #PasswordAuthentication yes 107c107 < #PidFile /var/run/sshd.pid --- > PidFile /var/run/sshd-internal.pid 112c112 < Banner /etc/issue --- > #Banner /some/path 122c122 < PermitRootLogin no --- > PermitRootLogin yes 127c127 < ListenAddress 213.123.213.1 --- > ListenAddress 10.10.0.1
Additionally, we also change the ListenAddress directive in the default sshd_config file. This time to make sure the standard SSH daemon will only listen on the public network interface:
# diff sshd_config sshd_config-internal (continued)
< #ListenAddress 0.0.0.0 --- > ListenAddress 213.123.213.1
In order to completely isolate both SSHD binaries from their start/stop sequence in /etc/rc.d/init.d we make a copy of the current sshd:
# which sshd /usr/sbin/sshd # ln -s /usr/sbin/sshd /usr/sbin/sshd-internal # ll /usr/sbin/sshd* 384 -rwxr-xr-x 1 root root 383148 Mar 21 21:49 /usr/sbin/sshd 0 lrwxrwxrwx 1 root root 4 Jul 16 21:47 /usr/sbin/sshd-internal -> sshd
Next, we tackle the start/stop sequence as we want to able to independently start & stop both daemons. We therefore copy the default SSH daemon start file:
# cd /etc/rc.d/init.d/ # cp sshd sshd-internal
Then we need to edit the new sshd-internal start/stop script to reflect paths to the sshd-internal instance:
# diff sshd sshd-internal
12,13c12,13 < # config: /etc/ssh/sshd_config < # pidfile: /var/run/sshd.pid --- > # config: /etc/ssh/sshd_config-internal > # pidfile: /var/run/sshd-internal.pid 19c19 < [ -f /etc/sysconfig/sshd ] && . /etc/sysconfig/sshd --- > [ -f /etc/sysconfig/sshd-internal ] && . /etc/sysconfig/sshd-internal 22c22 < prog="sshd" --- > prog="sshd-internal" 26c26 < SSHD=/usr/sbin/sshd --- > SSHD=/usr/sbin/sshd-internal 30c30 < PID_FILE=/var/run/sshd.pid --- > PID_FILE=/var/run/sshd-internal.pid
Notice that I did not only change the path to the new sshd binary and configuration file but also to a new PID file.
The new sshd-internal init script will try to source a configuration file in /etc/sysconfig/sshd-internal. In this configuration file we will tell the SSH daemon to start up with a different SSHD configuration file from the default /etc/ssh/sshd_config:
# cat /etc/sysconfig/sshd-internal OPTIONS="-f /etc/ssh/sshd_config-internal"
If your system has PAM enabled you will also need to provide a separate PAM configuration file for the new sshd-internal service. To keep things easy we are just going to link to the default sshd configuration file for PAM:
# cd /etc/pam.d # ln -s sshd sshd-internal
Finally we can (re-)start both SSH daemons with their split setup:
# service sshd restart # service sshd-internal start
The advantage of providing a separate sshd-internal binary through a symbolic link to the original sshd is that both running SSH daemons will always use the same application version. This is also true after an update of its RPM package for example.
Make sure your firewall disallows traffic towards the private network interface from the outside world .
Delicious
Digg
StumbleUpon
Propeller
Reddit
Magnoliacom
Google
Yahoo
Technorati
no authentication method
Anonymous — Wed, 17/02/2010 - 20:13I may have spoken too soon. my original instance of sshd is still working and allows access, but my new one complains after I type in username saying:
Disconnected: No supported authentication methods available.
please see:
diff sshd_config-external sshd_config
13c13
< Port 48722
---
> #Port 22
41c41
< PermitRootLogin no
---
> #PermitRootLogin yes
111c111
< PidFile /var/run/sshd-external.pid
---
> #PidFile /var/run/sshd.pid
117c117
< Banner /etc/ssh/banner-external
---
> #Banner none
(the 'external' one is the one which doesn't work)
anyone got any ideas? Will try to fix myself and answer own question - am probably just being dim.
keyboard-interactive?
patvdv — Thu, 18/02/2010 - 12:27Hi,
I would suggest doing a couple of things to help determining the cause of your problem:
The debug log and/or verbose output should give some more indication as to what could be going wrong.
Regards,
Pat.
nicely written
Anonymous — Wed, 17/02/2010 - 19:28not useful comment really - just to say i appreciate the clarity in writing. am on suse 11.1, tiny variations the init.d scripts, but still excellent guide/write-up.
in case anyone cares - am using the double ssh setup so that i can still allow lan-wide easy-access to very open ssh as tool for lots of diff engineering apps running on a compute server, AND second instance of sshd far more locked-down (certs, pwords, restricted users etc) and open to internet for FreeNX to use so that same compute server available as TS for remote users.
Thanks!
patvdv — Thu, 18/02/2010 - 12:28Glad the how-to was of good use to you
Regards,
Pat.
How about using a single ssh
Anonymous — Mon, 09/02/2009 - 04:20How about using a single ssh daemon listening on all local addresses and trying to connect to it by specifying the private address instead of the public address (i.e. doing a "ssh user@10.10.0.1" instead of "ssh user@213.123.213.1" in order to connect to the server).
Possibly not desireable
patvdv — Sat, 23/05/2009 - 11:03Hi,
This is possible if you let your SSHD listen on both network interfaces. But as I stated in my article, you would also then share the same security settings which is something I did not want.
Quote:
By default, the standard SSHD configuration on CentOS will cause the SSHD to listen on all available network interfaces. In my case that was on
eth0andeth1. So that is all that would have been required to make the secure copy work across the private network.However, the big disadvantage of this approach is that applied security settings for the running SSH daemon are valid for both networks. Typically, I never allow password based authentication on a public server but rather use SSH private/public keys instead. Additionally, direct root logins are also never allowed. Having to deal with this elevated security turned out to be rather a nuisance because opening terminal sessions and copying files always would have to happen using SSH keys and non-root logins.
Great tutorial but still some information missing
Anonymous — Tue, 02/12/2008 - 14:58I was able to get three SSH processes up and running but the tutorial makes very little reference as to WHY we need to modify:
# config: /etc/ssh/sshd_config
and also specify the config file in '/etc/sysconfig/sshd' file.
Also, while the scripts to start the instances of SSHD properly, the do not shut them down properly if using.
Editing config files
patvdv — Sat, 23/05/2009 - 10:59Hi,
We need to "undouble" the configuration for both SSHD to avoid that they use each other's settings. So you don't actually edit /etc/ssh/sshd_config but rather copy it to /etc/ssh/sshd_config-internal and then adjust the latter. Perhaps this is not clear from the 'diff' output.
The start/shutdown script works OK for me on Centos 5.x but your mileage may vary of course...