#!/bin/sh ### BEGIN INIT INFO # Provides: ssh # Required-Start: # Required-Stop: # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Position: S16ssh # Short-Description: Regular background program processing daemon # /etc/init.d/ssh: start and stop the OpenBSD "secure shell(tm)" daemon ### END INIT INFO # Eisfair: # add status message output # --------------------------------------------------------------------------- SSHD_OPTS="" set -e test -x /usr/sbin/sshd || exit 0 ( /usr/sbin/sshd -\? 2>&1 | grep -q OpenSSH ) 2>/dev/null || exit 0 if test -f /etc/default/ssh then . /etc/default/ssh fi . /lib/lsb/init-functions check_for_no_start() { # forget it if we're trying to start, and /etc/ssh/sshd_not_to_be_run exists if [ -e /etc/ssh/sshd_not_to_be_run ] then log_end_msg 0 log_warning_msg "OpenBSD Secure Shell server not in use (/etc/ssh/sshd_not_to_be_run)" exit 0 fi } check_privsep_dir() { # Create the PrivSep empty dir if necessary if [ ! -d /var/run/sshd ] then mkdir /var/run/sshd chmod 0755 /var/run/sshd fi } check_all_keyfiles() { [ -e /etc/ssh/ssh_host_key ] || ssh-keygen -q -f /etc/ssh/ssh_host_key -N '' -t rsa1 [ -e /etc/ssh/ssh_host_rsa_key ] || ssh-keygen -q -f /etc/ssh/ssh_host_rsa_key -N '' -t rsa [ -e /etc/ssh/ssh_host_dsa_key ] || ssh-keygen -q -f /etc/ssh/ssh_host_dsa_key -N '' -t dsa [ -e /etc/ssh/ssh_host_ecdsa_key ] || ssh-keygen -q -f /etc/ssh/ssh_host_ecdsa_key -N '' -t ecdsa chmod 600 /etc/ssh/ssh_host_key chmod 644 /etc/ssh/ssh_host_key.pub chmod 600 /etc/ssh/ssh_host_rsa_key chmod 644 /etc/ssh/ssh_host_rsa_key.pub chmod 600 /etc/ssh/ssh_host_dsa_key chmod 644 /etc/ssh/ssh_host_dsa_key.pub chmod 600 /etc/ssh/ssh_host_ecdsa_key chmod 644 /etc/ssh/ssh_host_ecdsa_key.pub } check_config() { if [ ! -e /etc/ssh/sshd_not_to_be_run ] then /usr/sbin/sshd -t || exit 1 fi } export PATH="${PATH:+$PATH:}/usr/sbin:/sbin" case "$1" in start) log_begin_msg "Starting OpenBSD Secure Shell server..." check_for_no_start check_privsep_dir check_all_keyfiles start-stop-daemon --start --quiet --pidfile /var/run/sshd.pid --exec /usr/sbin/sshd -- $SSHD_OPTS || log_end_msg 1 log_end_msg 0 ;; stop) log_begin_msg "Stopping OpenBSD Secure Shell server..." start-stop-daemon --stop --quiet --oknodo --pidfile /var/run/sshd.pid || log_end_msg 1 log_end_msg 0 ;; status) if [ -f /var/run/sshd.pid ] then echo "SSH using:" port=`grep '^Port ' /etc/ssh/sshd_config | sed "s/Port//g" | sed "s/ //g"` netstat -tan | grep ":$port " else log_action_msg "SSH is not running" exit 1 fi ;; reload|force-reload) log_begin_msg "Reloading OpenBSD Secure Shell server's configuration" check_for_no_start check_config start-stop-daemon --stop --signal 1 --quiet --oknodo --pidfile /var/run/sshd.pid --exec /usr/sbin/sshd || log_end_msg 1 log_end_msg 0 ;; restart) log_begin_msg "Restarting OpenBSD Secure Shell server..." check_privsep_dir check_config start-stop-daemon --stop --quiet --oknodo --retry 30 --pidfile /var/run/sshd.pid check_for_no_start start-stop-daemon --start --quiet --pidfile /var/run/sshd.pid --exec /usr/sbin/sshd -- $SSHD_OPTS || log_end_msg 1 log_end_msg 0 ;; *) log_action_msg "Usage: /etc/init.d/ssh {start|stop|status|reload|force-reload|restart}" exit 1 esac exit 0