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 adjusted by the Grml team so
13 # the script supports key-generation for ssh
17 # /etc/init.d/ssh: start and stop the OpenBSD "secure shell(tm)" daemon
19 test -x /usr/sbin/sshd || exit 0
20 ( /usr/sbin/sshd -\? 2>&1 | grep -q OpenSSH ) 2>/dev/null || exit 0
22 export SSHD_OOM_ADJUST=-17
23 if test -f /etc/default/ssh; then
27 # Are we in a virtual environment that doesn't support modifying
29 if grep -q 'envID:.*[1-9]' /proc/self/status; then
33 . /lib/lsb/init-functions
36 SSHD_OPTS="$SSHD_OPTS $2"
39 # Configurable options:
40 KEYGEN=/usr/bin/ssh-keygen
41 RSA1_KEY=/etc/ssh/ssh_host_key
42 RSA_KEY=/etc/ssh/ssh_host_rsa_key
43 DSA_KEY=/etc/ssh/ssh_host_dsa_key
44 ECDSA_KEY=/etc/ssh/ssh_host_ecdsa_key
46 # Are we running from init?
48 ([ "$previous" ] && [ "$runlevel" ]) || [ "$runlevel" = S ]
51 check_for_no_start() {
52 # forget it if we're trying to start, and /etc/ssh/sshd_not_to_be_run exists
53 if [ -e /etc/ssh/sshd_not_to_be_run ]; then
54 if [ "$1" = log_end_msg ]; then
57 if ! run_by_init; then
58 log_action_msg "OpenBSD Secure Shell server not in use (/etc/ssh/sshd_not_to_be_run)"
65 if [ ! -c /dev/null ]; then
66 if [ "$1" = log_end_msg ]; then
69 if ! run_by_init; then
70 log_action_msg "/dev/null is not a character device!"
77 # Create the PrivSep empty dir if necessary
78 if [ ! -d /var/run/sshd ]; then
80 chmod 0755 /var/run/sshd
85 if [ ! -e /etc/ssh/sshd_not_to_be_run ]; then
86 /usr/sbin/sshd $SSHD_OPTS -t || exit 1
90 export PATH="${PATH:+$PATH:}/usr/sbin:/sbin"
98 if ! test -f $RSA1_KEY ; then
99 log_action_msg "Generating SSH1 RSA host key..."
100 $KEYGEN -t rsa1 -f $RSA1_KEY -C '' -N '' || exit 1
103 if ! test -f $RSA_KEY ; then
104 log_action_msg "Generating SSH RSA host key..."
105 $KEYGEN -t rsa -f $RSA_KEY -C '' -N '' || exit 1
108 if ! test -f $DSA_KEY ; then
109 log_action_msg "Generating SSH2 DSA host key..."
110 $KEYGEN -t dsa -f $DSA_KEY -C '' -N '' || exit 1
112 if ! test -f "$ECDSA_KEY" && grep -q "$ECDSA_KEY" /etc/ssh/sshd_config ; then
113 log_action_msg "Generating SSH2 ECDSA host key..."
114 $KEYGEN -t ecdsa -f "$ECDSA_KEY" -C '' -N '' || exit 1
117 log_daemon_msg "Starting OpenBSD Secure Shell server" "sshd"
118 if start-stop-daemon --start --quiet --oknodo --pidfile /var/run/sshd.pid --exec /usr/sbin/sshd -- $SSHD_OPTS; then
125 log_daemon_msg "Stopping OpenBSD Secure Shell server" "sshd"
126 if start-stop-daemon --stop --quiet --oknodo --pidfile /var/run/sshd.pid; then
136 log_daemon_msg "Reloading OpenBSD Secure Shell server's configuration" "sshd"
137 if start-stop-daemon --stop --signal 1 --quiet --oknodo --pidfile /var/run/sshd.pid --exec /usr/sbin/sshd; then
147 log_daemon_msg "Restarting OpenBSD Secure Shell server" "sshd"
148 start-stop-daemon --stop --quiet --oknodo --retry 30 --pidfile /var/run/sshd.pid
149 check_for_no_start log_end_msg
150 check_dev_null log_end_msg
151 if start-stop-daemon --start --quiet --oknodo --pidfile /var/run/sshd.pid --exec /usr/sbin/sshd -- $SSHD_OPTS; then
161 log_daemon_msg "Restarting OpenBSD Secure Shell server" "sshd"
163 start-stop-daemon --stop --quiet --retry 30 --pidfile /var/run/sshd.pid
169 check_for_no_start log_end_msg
170 check_dev_null log_end_msg
171 if start-stop-daemon --start --quiet --oknodo --pidfile /var/run/sshd.pid --exec /usr/sbin/sshd -- $SSHD_OPTS; then
179 log_progress_msg "(not running)"
184 log_progress_msg "(failed to stop)"
191 status_of_proc -p /var/run/sshd.pid /usr/sbin/sshd sshd && exit 0 || exit $?
195 log_action_msg "Usage: /etc/init.d/ssh {start|stop|reload|force-reload|restart|try-restart|status}"
201 ## END OF FILE #################################################################