3 # Init file for OpenSSH server daemon
5 # chkconfig: 2345 55 25
6 # description: OpenSSH server daemon
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
15 # source function library
16 . /etc/rc.d/init.d/functions
18 # pull in sysconfig settings
19 [ -f /etc/sysconfig/sshd ] && . /etc/sysconfig/sshd
24 # Some functions to make the below more readable
25 KEYGEN=/usr/bin/ssh-keygen
27 RSA1_KEY=/etc/ssh/ssh_host_key
28 RSA_KEY=/etc/ssh/ssh_host_rsa_key
29 DSA_KEY=/etc/ssh/ssh_host_dsa_key
30 PID_FILE=/var/run/sshd.pid
33 if [ ! -s $RSA1_KEY ]; then
34 echo -n $"Generating SSH1 RSA host key: "
35 if $KEYGEN -q -t rsa1 -f $RSA1_KEY -C '' -N '' >&/dev/null; then
37 chmod 644 $RSA1_KEY.pub
38 success $"RSA1 key generation"
41 failure $"RSA1 key generation"
49 if [ ! -s $RSA_KEY ]; then
50 echo -n $"Generating SSH2 RSA host key: "
51 if $KEYGEN -q -t rsa -f $RSA_KEY -C '' -N '' >&/dev/null; then
53 chmod 644 $RSA_KEY.pub
54 success $"RSA key generation"
57 failure $"RSA key generation"
65 if [ ! -s $DSA_KEY ]; then
66 echo -n $"Generating SSH2 DSA host key: "
67 if $KEYGEN -q -t dsa -f $DSA_KEY -C '' -N '' >&/dev/null; then
69 chmod 644 $DSA_KEY.pub
70 success $"DSA key generation"
73 failure $"DSA key generation"
80 do_restart_sanity_check()
84 if [ ! "$RETVAL" = 0 ]; then
85 failure $"Configuration file or keys are invalid"
92 # Create keys if necessary
97 echo -n $"Starting $prog:"
98 initlog -c "$SSHD $OPTIONS" && success || failure
100 [ "$RETVAL" = 0 ] && touch /var/lock/subsys/sshd
106 echo -n $"Stopping $prog:"
109 [ "$RETVAL" = 0 ] && rm -f /var/lock/subsys/sshd
115 echo -n $"Reloading $prog:"
136 if [ -f /var/lock/subsys/sshd ] ; then
137 do_restart_sanity_check
138 if [ "$RETVAL" = 0 ] ; then
151 echo $"Usage: $0 {start|stop|restart|reload|condrestart|status}"