Damien Miller | 0623076 | 1999-10-28 14:03:14 +1000 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # Init file for OpenSSH server daemon |
| 4 | # |
| 5 | # chkconfig: 2345 55 25 |
| 6 | # description: OpenSSH server daemon |
| 7 | # |
Damien Miller | a37010e | 1999-10-29 09:18:29 +1000 | [diff] [blame] | 8 | # processname: sshd |
| 9 | # config: /etc/ssh/ssh_host_key |
| 10 | # config: /etc/ssh/ssh_host_key.pub |
| 11 | # config: /etc/ssh/ssh_random_seed |
| 12 | # config: /etc/ssh/sshd_config |
| 13 | # pidfile: /var/run/sshd.pid |
Damien Miller | 0623076 | 1999-10-28 14:03:14 +1000 | [diff] [blame] | 14 | |
| 15 | # source function library |
| 16 | . /etc/rc.d/init.d/functions |
| 17 | |
| 18 | RETVAL=0 |
| 19 | |
Damien Miller | ab8d192 | 2000-08-08 16:53:28 +1000 | [diff] [blame] | 20 | # Some functions to make the below more readable |
| 21 | KEYGEN=/usr/bin/ssh-keygen |
| 22 | RSA_KEY=/etc/ssh/ssh_host_key |
| 23 | DSA_KEY=/etc/ssh/ssh_host_dsa_key |
| 24 | PID_FILE=/var/run/sshd.pid |
| 25 | do_rsa_keygen() { |
| 26 | if $KEYGEN -R && ! test -f $RSA_KEY ; then |
| 27 | echo -n "Generating SSH RSA host key: " |
| 28 | if $KEYGEN -q -b 1024 -f $RSA_KEY -C '' -N '' >&/dev/null; then |
| 29 | success "RSA key generation" |
| 30 | echo |
| 31 | else |
| 32 | failure "RSA key generation" |
| 33 | echo |
| 34 | exit 1 |
| 35 | fi |
| 36 | fi |
| 37 | } |
| 38 | do_dsa_keygen() { |
| 39 | if ! test -f $DSA_KEY ; then |
| 40 | echo -n "Generating SSH DSA host key: " |
| 41 | if $KEYGEN -q -d -b 1024 -f $DSA_KEY -C '' -N '' >&/dev/null; then |
| 42 | success "DSA key generation" |
| 43 | echo |
| 44 | else |
| 45 | failure "DSA key generation" |
| 46 | echo |
| 47 | exit 1 |
| 48 | fi |
| 49 | fi |
| 50 | } |
| 51 | |
Damien Miller | 0623076 | 1999-10-28 14:03:14 +1000 | [diff] [blame] | 52 | case "$1" in |
Damien Miller | ab8d192 | 2000-08-08 16:53:28 +1000 | [diff] [blame] | 53 | start) |
| 54 | # Create keys if necessary |
| 55 | do_rsa_keygen; |
| 56 | do_dsa_keygen; |
| 57 | |
| 58 | echo -n "Starting sshd: " |
| 59 | if [ ! -f $PID_FILE ] ; then |
Damien Miller | 123cbe8 | 2000-09-03 19:14:58 +1100 | [diff] [blame] | 60 | sshd |
Damien Miller | ab8d192 | 2000-08-08 16:53:28 +1000 | [diff] [blame] | 61 | RETVAL=$? |
Damien Miller | 123cbe8 | 2000-09-03 19:14:58 +1100 | [diff] [blame] | 62 | if [ "$RETVAL" = "0" ] ; then |
| 63 | success "sshd startup" |
| 64 | touch /var/lock/subsys/sshd |
| 65 | else |
| 66 | failure "sshd startup" |
| 67 | fi |
Damien Miller | ab8d192 | 2000-08-08 16:53:28 +1000 | [diff] [blame] | 68 | fi |
| 69 | echo |
| 70 | ;; |
| 71 | stop) |
| 72 | echo -n "Shutting down sshd: " |
| 73 | if [ -f $PID_FILE ] ; then |
| 74 | killproc sshd |
| 75 | [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/sshd |
| 76 | fi |
| 77 | echo |
| 78 | ;; |
| 79 | restart) |
| 80 | $0 stop |
| 81 | $0 start |
| 82 | RETVAL=$? |
| 83 | ;; |
| 84 | status) |
| 85 | status sshd |
| 86 | RETVAL=$? |
| 87 | ;; |
| 88 | *) |
| 89 | echo "Usage: sshd {start|stop|restart|status}" |
| 90 | exit 1 |
| 91 | ;; |
Damien Miller | 0623076 | 1999-10-28 14:03:14 +1000 | [diff] [blame] | 92 | esac |
| 93 | |
| 94 | exit $RETVAL |