5 kx #!/bin/sh
5 kx # Start/stop/restart the secure shell server:
5 kx
5 kx # Source options
5 kx if [ -r /etc/default/sshd ]; then
5 kx . /etc/default/sshd
5 kx fi
5 kx
5 kx sshd_start() {
5 kx # Create host keys if needed.
5 kx if [ ! -f /etc/ssh/ssh_host_dsa_key ]; then
5 kx /usr/bin/ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key -N ''
5 kx fi
5 kx if [ ! -f /etc/ssh/ssh_host_rsa_key ]; then
5 kx /usr/bin/ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N ''
5 kx fi
5 kx if [ ! -f /etc/ssh/ssh_host_ecdsa_key ]; then
5 kx /usr/bin/ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key -N ''
5 kx fi
5 kx if [ ! -f /etc/ssh/ssh_host_ed25519_key ]; then
5 kx /usr/bin/ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key -N ''
5 kx fi
5 kx # Catch any new host key types not yet created above:
5 kx /usr/bin/ssh-keygen -A
5 kx # Start the sshd daemon:
5 kx /usr/sbin/sshd $SSHD_OPTS
5 kx }
5 kx
5 kx sshd_stop() {
5 kx killall sshd
5 kx }
5 kx
5 kx sshd_restart() {
5 kx if [ -r /var/run/sshd.pid ]; then
5 kx echo "WARNING: killing listener process only. To kill every sshd process, you must"
5 kx echo " use 'rc.sshd stop'. 'rc.sshd restart' kills only the parent sshd to"
5 kx echo " allow an admin logged in through sshd to use 'rc.sshd restart' without"
5 kx echo " being cut off. If sshd has been upgraded, new connections will now"
5 kx echo " use the new version, which should be a safe enough approach."
5 kx kill `cat /var/run/sshd.pid`
5 kx else
5 kx echo "WARNING: There does not appear to be a parent instance of sshd running."
5 kx echo " If you really want to kill all running instances of sshd (including"
5 kx echo " any sessions currently in use), run '/etc/rc.d/rc.sshd stop' instead."
5 kx exit 1
5 kx fi
5 kx sleep 1
5 kx sshd_start
5 kx }
5 kx
5 kx case "$1" in
5 kx 'start')
5 kx sshd_start
5 kx ;;
5 kx 'stop')
5 kx sshd_stop
5 kx ;;
5 kx 'restart')
5 kx sshd_restart
5 kx ;;
5 kx *)
5 kx echo "usage $0 start|stop|restart"
5 kx esac