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 RSA_KEY=/etc/ssh/ssh_host_rsa_key
28 DSA_KEY=/etc/ssh/ssh_host_dsa_key
29 PID_FILE=/var/run/sshd.pid
38 case "`type -type success`" in
54 case "`type -type failure`" in
64 if [ ! -s $RSA_KEY ]; then
65 echo -n "Generating SSH2 RSA host key: "
66 if $KEYGEN -q -t rsa -f $RSA_KEY -C '' -N '' >&/dev/null; then
68 chmod 644 $RSA_KEY.pub
69 my_success "RSA key generation"
72 my_failure "RSA key generation"
79 if [ ! -s $DSA_KEY ]; then
80 echo -n "Generating SSH2 DSA host key: "
81 if $KEYGEN -q -t dsa -f $DSA_KEY -C '' -N '' >&/dev/null; then
83 chmod 644 $DSA_KEY.pub
84 my_success "DSA key generation"
87 my_failure "DSA key generation"
93 do_restart_sanity_check() {
96 if [ ! "$RETVAL" = 0 ]; then
97 my_failure "Configuration file or keys"
105 # Create keys if necessary
109 echo -n "Starting sshd: "
110 if [ ! -f $PID_FILE ] ; then
113 if [ "$RETVAL" = "0" ] ; then
114 my_success "sshd startup" "sshd"
115 touch /var/lock/subsys/sshd
117 my_failure "sshd startup" ""
123 echo -n "Shutting down sshd: "
124 if [ -f $PID_FILE ] ; then
127 [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/sshd
132 do_restart_sanity_check
138 if [ -f /var/lock/subsys/sshd ] ; then
139 do_restart_sanity_check
150 echo "Usage: sshd {start|stop|restart|status|condrestart}"