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 [ -f /etc/sysconfig/sshd ] && . /etc/sysconfig/sshd
22 # Some functions to make the below more readable
23 KEYGEN=/usr/bin/ssh-keygen
24 RSA1_KEY=/etc/ssh/ssh_host_key
25 RSA_KEY=/etc/ssh/ssh_host_rsa_key
26 DSA_KEY=/etc/ssh/ssh_host_dsa_key
27 PID_FILE=/var/run/sshd.pid
35 case "`type -type success`" in
51 case "`type -type failure`" in
61 if ! test -f $RSA1_KEY ; then
62 echo -n "Generating SSH1 RSA host key: "
63 if $KEYGEN -q -t rsa1 -f $RSA1_KEY -C '' -N '' >&/dev/null; then
64 my_success "RSA1 key generation"
67 my_failure "RSA1 key generation"
74 if ! test -f $RSA_KEY ; then
75 echo -n "Generating SSH2 RSA host key: "
76 if $KEYGEN -q -t rsa -f $RSA_KEY -C '' -N '' >&/dev/null; then
77 my_success "RSA key generation"
80 my_failure "RSA key generation"
87 if ! test -f $DSA_KEY ; then
88 echo -n "Generating SSH2 DSA host key: "
89 if $KEYGEN -q -t dsa -f $DSA_KEY -C '' -N '' >&/dev/null; then
90 my_success "DSA key generation"
93 my_failure "DSA key generation"
99 do_restart_sanity_check() {
102 if [ ! "$RETVAL" = 0 ]; then
103 my_failure "Configuration file or keys"
112 # Create keys if necessary
117 echo -n "Starting sshd: "
118 if [ ! -f $PID_FILE ] ; then
121 if [ "$RETVAL" = "0" ] ; then
122 my_success "sshd startup" "sshd"
123 touch /var/lock/subsys/sshd
125 my_failure "sshd startup" ""
131 echo -n "Shutting down sshd: "
132 if [ -f $PID_FILE ] ; then
135 [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/sshd
140 do_restart_sanity_check
146 if [ -f /var/lock/subsys/sshd ] ; then
147 do_restart_sanity_check
158 echo "Usage: sshd {start|stop|restart|status|condrestart}"