| 1 | #!/bin/sh |
| 2 | # |
| 3 | # /etc/rc.d/sshd: start/stop ssh daemon |
| 4 | # |
| 5 | |
| 6 | SSD=/sbin/start-stop-daemon |
| 7 | PROG=/usr/sbin/sshd |
| 8 | PID=/var/run/sshd.pid |
| 9 | KEYGEN=/usr/bin/ssh-keygen |
| 10 | SSHDIR=/etc/ssh |
| 11 | |
| 12 | create_keys() { |
| 13 | if [ ! -f $SSHDIR/ssh_host_rsa_key ]; then |
| 14 | $KEYGEN -q -t rsa -b 2048 -N "" -f $SSHDIR/ssh_host_rsa_key |
| 15 | fi |
| 16 | if [ ! -f $SSHDIR/ssh_host_dsa_key ]; then |
| 17 | $KEYGEN -q -t dsa -N "" -f $SSHDIR/ssh_host_dsa_key |
| 18 | fi |
| 19 | if [ ! -f $SSHDIR/ssh_host_ecdsa_key ]; then |
| 20 | $KEYGEN -q -t ecdsa -b 521 -N "" -f $SSHDIR/ssh_host_ecdsa_key |
| 21 | fi |
| 22 | if [ ! -f $SSHDIR/ssh_host_ed25519_key ]; then |
| 23 | $KEYGEN -q -t ed25519 -N "" -f $SSHDIR/ssh_host_ed25519_key |
| 24 | fi |
| 25 | } |
| 26 | |
| 27 | case $1 in |
| 28 | start) |
| 29 | create_keys |
| 30 | $SSD --start --pidfile $PID --exec $PROG |
| 31 | ;; |
| 32 | stop) |
| 33 | $SSD --stop --retry 10 --pidfile $PID |
| 34 | ;; |
| 35 | restart) |
| 36 | $0 stop |
| 37 | $0 start |
| 38 | ;; |
| 39 | status) |
| 40 | $SSD --status --pidfile $PID |
| 41 | case $? in |
| 42 | 0) echo "$PROG is running with pid $(cat $PID)" ;; |
| 43 | 1) echo "$PROG is not running but the pid file $PID exists" ;; |
| 44 | 3) echo "$PROG is not running" ;; |
| 45 | 4) echo "Unable to determine the program status" ;; |
| 46 | esac |
| 47 | ;; |
| 48 | *) |
| 49 | echo "usage: $0 [start|stop|restart|status]" |
| 50 | ;; |
| 51 | esac |
| 52 | |
| 53 | # End of file |