1

I've configured a second instance of my ssh-server. "ssh" will listen to port 22 but only allows private/public key login (via phabricator). "ssh2" will listen to port 266 with default sshd_config options.

This worked well on Trusty Tahr, but since I've upgraded to Xenial, "ssh2" won't start. It says

/etc/init.d/ssh2: 5: /etc/default/ssh2: /etc/ssh2/sshd_config: Permission denied

Setup Port 266:

/etc/ssh:

sudo cp -r /etc/ssh /etc/ssh2

Changes in /etc/ssh2/sshd_config:

Port 266
HostKey /etc/ssh2/ssh_host_rsa_key
HostKey /etc/ssh2/ssh_host_dsa_key
HostKey /etc/ssh2/ssh_host_ecdsa_key
HostKey /etc/ssh2/ssh_host_ed25519_key
PidFile /var/run/sshd2.pid

/etc/default/ssh:

sudo cp /etc/default/ssh /etc/default/ssh2

and changed its content to:

SSHD_OPTS=-f /etc/ssh2/sshd_config

/etc/init/ssh.conf:

sudo cp /etc/init/ssh.conf /etc/init/ssh2.conf

I changed all occurrences of ssh/sshd to ssh2/sshd2 and renamed env SSH_SIGSTOP=1 to env SSH2_SIGSTOP=1.

Symbolic links:

sudo ln -s /usr/sbin/sshd /usr/sbin/sshd2
sudo ln -s /etc/pam.d/sshd /etc/pam.d/sshd2
sudo ln -s /etc/init.d/ssh2 /etc/rc2.d/S03ssh2
sudo ln -s /etc/init.d/ssh2 /etc/rc3.d/S03ssh2
sudo ln -s /etc/init.d/ssh2 /etc/rc4.d/S03ssh2
sudo ln -s /etc/init.d/ssh2 /etc/rc5.d/S03ssh2

/etc/init.d/ssh:

sudo cp /etc/init.d/ssh /etc/init.d/ssh2

I changed all occurrences of "ssh"/"sshd" to "ssh2"/"sshd2".

Finally I updated iptables:

sudo iptables -A INPUT -p tcp --dport 266 -j ACCEPT

Now, if I want to start service ssh2 I get the following error:

Job for ssh2.service failed because the control process exited with error code. See "systemctl status ssh2.service" and "journalctl -xe" for details.

systemctl status ssh2.service:

● ssh2.service - LSB: OpenBSD Secure Shell server Loaded: loaded (/etc/init.d/ssh2; bad; vendor preset: enabled) Active: failed (Result: exit-code) since Sat 2016-11-19 15:53:46 CET; 44s ago Docs: man:systemd-sysv-generator(8) Process: 2046 ExecStart=/etc/init.d/ssh2 start (code=exited, status=126)

Nov 19 15:53:46 cloud systemd[1]: Starting LSB: OpenBSD Secure Shell server... Nov 19 15:53:46 cloud ssh2[2046]: /etc/init.d/ssh2: 5: /etc/default/ssh2: /etc/ssh2/sshd_config: Permission denied Nov 19 15:53:46 cloud systemd[1]: ssh2.service: Control process exited, code=exited status=126 Nov 19 15:53:46 cloud systemd[1]: Failed to start LSB: OpenBSD Secure Shell server. Nov 19 15:53:46 cloud systemd[1]: ssh2.service: Unit entered failed state. Nov 19 15:53:46 cloud systemd[1]: ssh2.service: Failed with result 'exit-code'.

journalctl -xe:

Starting LSB: OpenBSD Secure Shell server... Subject: Unit ssh2.service has begun start-up Defined-By: systemd Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel Unit ssh2.service has begun starting up. Nov 19 15:55:57 cloud ssh2[2098]: /etc/init.d/ssh2: 5: /etc/default/ssh2: /etc/ssh2/sshd_config: Permission denied Nov 19 15:55:57 cloud systemd[1]: ssh2.service: Control process exited, code=exited status=126 Nov 19 15:55:57 cloud systemd[1]: Failed to start LSB: OpenBSD Secure Shell server. Subject: Unit ssh2.service has failed Defined-By: systemd Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel Unit ssh2.service has failed. The result is failed. Nov 19 15:55:57 cloud systemd[1]: ssh2.service: Unit entered failed state. Nov 19 15:55:57 cloud systemd[1]: ssh2.service: Failed with result 'exit-code'.

(I removed the double dashes from journalctl -xe).

File permissions:

/etc/ssh2/:

-rw-r--r--   1 root root 300261 Aug 11 18:24 moduli
-rw-r--r--   1 root root   1756 Aug 11 18:24 ssh_config
-rw-------   1 root root   2556 Nov 17 23:51 sshd_config
-rw-------   1 root root    668 Apr 18  2015 ssh_host_dsa_key
-rw-r--r--   1 root root    600 Apr 18  2015 ssh_host_dsa_key.pub
-rw-------   1 root root    227 Apr 18  2015 ssh_host_ecdsa_key
-rw-r--r--   1 root root    172 Apr 18  2015 ssh_host_ecdsa_key.pub
-rw-------   1 root root    399 Aug 19  2015 ssh_host_ed25519_key
-rw-r--r--   1 root root     92 Aug 19  2015 ssh_host_ed25519_key.pub
-rw-------   1 root root   1675 Apr 18  2015 ssh_host_rsa_key
-rw-r--r--   1 root root    392 Apr 18  2015 ssh_host_rsa_key.pub
-rw-r--r--   1 root root    338 Nov 17 19:02 ssh_import_id

/etc/ssh2/:

-rw-r--r--   1 root root 300261 Nov 17 19:32 moduli
-rw-r--r--   1 root root   1756 Nov 17 19:35 ssh_config
-rw-r--r--   1 root root   2562 Nov 19 14:07 sshd_config
-rw-------   1 root root    668 Mar  1  2016 ssh_host_dsa_key
-rw-r--r--   1 root root    600 Mar  1  2016 ssh_host_dsa_key.pub
-rw-------   1 root root    227 Mar  1  2016 ssh_host_ecdsa_key
-rw-r--r--   1 root root    172 Mar  1  2016 ssh_host_ecdsa_key.pub
-rw-------   1 root root    399 Mar  1  2016 ssh_host_ed25519_key
-rw-r--r--   1 root root     92 Mar  1  2016 ssh_host_ed25519_key.pub
-rw-------   1 root root   1675 Mar  1  2016 ssh_host_rsa_key
-rw-r--r--   1 root root    392 Mar  1  2016 ssh_host_rsa_key.pub
-rw-r--r--   1 root root    338 Feb 28  2016 ssh_import_id

/etc/default/ (trimmed):

-rw-r--r--   1 root root   156 Nov 19 15:18 ssh
-rw-r--r--   1 root root   157 Feb 29  2016 ssh2

/etc/init.d/ (trimmed):

-rwxr-xr-x   1 root root  4077 Nov 18 00:38 ssh
-rwxr-xr-x   1 root root  4121 Nov 18 01:27 ssh2

Service-Status: SSH:

ssh.service - OpenBSD Secure Shell server
   Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled)
   Active: active (running) since Sat 2016-11-19 15:18:47 CET; 46min ago
 Main PID: 846 (sshd)
   CGroup: /system.slice/ssh.service
           └─846 /usr/sbin/sshd -D -f /etc/ssh/sshd_config

SSH2:

ssh2.service - LSB: OpenBSD Secure Shell server
   Loaded: loaded (/etc/init.d/ssh2; bad; vendor preset: enabled)
   Active: failed (Result: exit-code) since Sat 2016-11-19 15:18:44 CET; 47min ago
     Docs: man:systemd-sysv-generator(8)
  Process: 375 ExecStart=/etc/init.d/ssh2 start (code=exited, status=126)

Nov 19 15:18:44 cloud systemd[1]: Starting LSB: OpenBSD Secure Shell server...
Nov 19 15:18:44 cloud ssh2[375]: /etc/init.d/ssh2: 5: /etc/default/ssh2: /etc/ssh2/sshd_config: Permission denied
Nov 19 15:18:44 cloud systemd[1]: ssh2.service: Control process exited, code=exited status=126
Nov 19 15:18:44 cloud systemd[1]: Failed to start LSB: OpenBSD Secure Shell server2.
Nov 19 15:18:44 cloud systemd[1]: ssh2.service: Unit entered failed state.
Nov 19 15:18:44 cloud systemd[1]: ssh2.service: Failed with result 'exit-code'.

Executing the following command (from /etc/initi.d/ssh2) will start the ssh server without any errors. Starting the service via "service ssh2 start" will result in errors!

start-stop-daemon --start --quiet --oknodo --pidfile /var/run/sshd2.pid --exec /usr/sbin/sshd2 -- -f /etc/ssh2/sshd_config

Summarized:

  • service ssh is active (Port 22, currently with default settings)
  • service ssh2 won't start
  • both services used to work as intended before upgrading to Xenial

I hope, somebody knows, what to do. Thanks in advance!

Update: Added the start-stop-daemon line.

  • 1
    If you have solved your problem, please consider posting the solution as an answer and not as an update to the question. – muru Nov 19 '16 at 18:19
  • Oh, I haven't seen the answer-button. Thanks! – schranktuer Nov 19 '16 at 18:25
1

Now both ssh instances are running! What did the trick?

I've done the following steps:

  • Set SSHD_OPTS=-f /etc/ssh2/sshd_config to SSHD_OPTS= in /etc/default/ssh2
  • Set exec /usr/sbin/sshd2 -D to exec /usr/sbin/sshd2 -D -f /etc/ssh2/sshd_config in /etc/init/ssh2.conf
  • Uncomment SSHD_OPTS in /etc/init.d/ssh2
  • Set /usr/sbin/sshd2 $SSHD_OPTS -t || exit 1 to /usr/sbin/sshd2 -f /etc/ssh2/sshd_config -t || exit 1 in /etc/init.d/ssh2
  • Set if start-stop-daemon --start --quiet --oknodo --pidfile /var/run/sshd2.pid --exec /usr/sbin/sshd2 -- $SSHD_OPTS; then to if start-stop-daemon --start --quiet --oknodo --pidfile /var/run/sshd2.pid --exec /usr/sbin/sshd2 -- -f /etc/ssh2/sshd_config; then in /etc/init.d/ssh2 (3 occurrences!)
  • reboot

After the reboot both services were running.

0

Your system is using systemd so you should probably use that.

Copy the current ssh service-file from /lib/systemd/system/ssh.service to /etc/systemd/system/ssh2.service, edit the new file to your liking and then command: sudo systemctl enable ssh2 && sudo systemctl start ssh2

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.