blob: a30d48065134c182f6f701512f6db72f9eecd536 [file] [log] [blame]
Damien Miller06230761999-10-28 14:03:14 +10001#!/bin/bash
2
3# Init file for OpenSSH server daemon
4#
5# chkconfig: 2345 55 25
6# description: OpenSSH server daemon
7#
Damien Millera37010e1999-10-29 09:18:29 +10008# 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 Miller06230761999-10-28 14:03:14 +100014
15# source function library
16. /etc/rc.d/init.d/functions
17
18RETVAL=0
19
Damien Millerab8d1922000-08-08 16:53:28 +100020# Some functions to make the below more readable
21KEYGEN=/usr/bin/ssh-keygen
22RSA_KEY=/etc/ssh/ssh_host_key
23DSA_KEY=/etc/ssh/ssh_host_dsa_key
24PID_FILE=/var/run/sshd.pid
25do_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}
38do_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 Miller06230761999-10-28 14:03:14 +100052case "$1" in
Damien Millerab8d1922000-08-08 16:53:28 +100053 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 Miller123cbe82000-09-03 19:14:58 +110060 sshd
Damien Millerab8d1922000-08-08 16:53:28 +100061 RETVAL=$?
Damien Miller123cbe82000-09-03 19:14:58 +110062 if [ "$RETVAL" = "0" ] ; then
63 success "sshd startup"
64 touch /var/lock/subsys/sshd
65 else
66 failure "sshd startup"
67 fi
Damien Millerab8d1922000-08-08 16:53:28 +100068 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 Miller06230761999-10-28 14:03:14 +100092esac
93
94exit $RETVAL