5 # Required-Start: $remote_fs $syslog
6 # Required-Stop: $remote_fs $syslog
7 # Default-Start: 2 3 4 5
9 # Short-Description: OpenBSD Secure Shell server
12 # Notice: this file has been slightly adjusted by the
13 # Grml team so the script supports key-generation
15 # Configurable options:
16 KEYGEN=/usr/bin/ssh-keygen
17 RSA_KEY=/etc/ssh/ssh_host_rsa_key
18 DSA_KEY=/etc/ssh/ssh_host_dsa_key
19 ECDSA_KEY=/etc/ssh/ssh_host_ecdsa_key
20 ED25519_KEY=/etc/ssh/ssh_host_ed25519_key
24 # /etc/init.d/ssh: start and stop the OpenBSD "secure shell(tm)" daemon
26 test -x /usr/sbin/sshd || exit 0
27 ( /usr/sbin/sshd -\? 2>&1 | grep -q OpenSSH ) 2>/dev/null || exit 0
31 if test -f /etc/default/ssh; then
35 . /lib/lsb/init-functions
38 SSHD_OPTS="$SSHD_OPTS $2"
41 # Are we running from init?
43 ([ "$previous" ] && [ "$runlevel" ]) || [ "$runlevel" = S ]
47 if init_is_upstart; then
52 check_for_no_start() {
53 # forget it if we're trying to start, and /etc/ssh/sshd_not_to_be_run exists
54 if [ -e /etc/ssh/sshd_not_to_be_run ]; then
55 if [ "$1" = log_end_msg ]; then
58 if ! run_by_init; then
59 log_action_msg "OpenBSD Secure Shell server not in use (/etc/ssh/sshd_not_to_be_run)" || true
66 if [ ! -c /dev/null ]; then
67 if [ "$1" = log_end_msg ]; then
70 if ! run_by_init; then
71 log_action_msg "/dev/null is not a character device!" || true
78 # Create the PrivSep empty dir if necessary
79 if [ ! -d /var/run/sshd ]; then
81 chmod 0755 /var/run/sshd
86 if [ ! -e /etc/ssh/sshd_not_to_be_run ]; then
87 /usr/sbin/sshd $SSHD_OPTS -t || exit 1
93 if ! test -f $RSA_KEY ; then
94 log_action_msg "Generating SSH2 RSA host key..."
95 $KEYGEN -t rsa -f $RSA_KEY -C '' -N '' || exit 1
98 if ! test -f $DSA_KEY ; then
99 log_action_msg "Generating SSH2 DSA host key..."
100 $KEYGEN -t dsa -f $DSA_KEY -C '' -N '' || exit 1
103 if ! test -f "$ECDSA_KEY" && grep -q "$ECDSA_KEY" /etc/ssh/sshd_config ; then
104 log_action_msg "Generating SSH2 ECDSA host key..."
105 $KEYGEN -t ecdsa -f "$ECDSA_KEY" -C '' -N '' || exit 1
108 if ! test -f "$ED25519_KEY" && grep -q "$ED25519_KEY" /etc/ssh/sshd_config ; then
109 log_action_msg "Generating SSH2 ED25519 host key..."
110 $KEYGEN -t ed25519 -f "$ED25519_KEY" -C '' -N '' || exit 1
114 export PATH="${PATH:+$PATH:}/usr/sbin:/sbin"
123 log_daemon_msg "Starting OpenBSD Secure Shell server" "sshd" || true
124 if start-stop-daemon --start --quiet --oknodo --pidfile /var/run/sshd.pid --exec /usr/sbin/sshd -- $SSHD_OPTS; then
125 log_end_msg 0 || true
127 log_end_msg 1 || true
132 log_daemon_msg "Stopping OpenBSD Secure Shell server" "sshd" || true
133 if start-stop-daemon --stop --quiet --oknodo --pidfile /var/run/sshd.pid; then
134 log_end_msg 0 || true
136 log_end_msg 1 || true
145 log_daemon_msg "Reloading OpenBSD Secure Shell server's configuration" "sshd" || true
146 if start-stop-daemon --stop --signal 1 --quiet --oknodo --pidfile /var/run/sshd.pid --exec /usr/sbin/sshd; then
147 log_end_msg 0 || true
149 log_end_msg 1 || true
158 log_daemon_msg "Restarting OpenBSD Secure Shell server" "sshd" || true
159 start-stop-daemon --stop --quiet --oknodo --retry 30 --pidfile /var/run/sshd.pid
160 check_for_no_start log_end_msg
161 check_dev_null log_end_msg
162 if start-stop-daemon --start --quiet --oknodo --pidfile /var/run/sshd.pid --exec /usr/sbin/sshd -- $SSHD_OPTS; then
163 log_end_msg 0 || true
165 log_end_msg 1 || true
174 log_daemon_msg "Restarting OpenBSD Secure Shell server" "sshd" || true
176 start-stop-daemon --stop --quiet --retry 30 --pidfile /var/run/sshd.pid || RET="$?"
180 check_for_no_start log_end_msg
181 check_dev_null log_end_msg
182 if start-stop-daemon --start --quiet --oknodo --pidfile /var/run/sshd.pid --exec /usr/sbin/sshd -- $SSHD_OPTS; then
183 log_end_msg 0 || true
185 log_end_msg 1 || true
190 log_progress_msg "(not running)" || true
191 log_end_msg 0 || true
195 log_progress_msg "(failed to stop)" || true
196 log_end_msg 1 || true
203 status_of_proc -p /var/run/sshd.pid /usr/sbin/sshd sshd && exit 0 || exit $?
207 log_action_msg "Usage: /etc/init.d/ssh {start|stop|reload|force-reload|restart|try-restart|status}" || true