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
39 case "`type -type success`" in
55 case "`type -type failure`" in
65 if [ ! -s $RSA1_KEY ]; then
66 echo -n "Generating SSH1 RSA host key: "
67 if $KEYGEN -q -t rsa1 -f $RSA1_KEY -C '' -N '' >&/dev/null; then
69 chmod 644 $RSA1_KEY.pub
70 my_success "RSA1 key generation"
73 my_failure "RSA1 key generation"
80 if [ ! -s $RSA_KEY ]; then
81 echo -n "Generating SSH2 RSA host key: "
82 if $KEYGEN -q -t rsa -f $RSA_KEY -C '' -N '' >&/dev/null; then
84 chmod 644 $RSA_KEY.pub
85 my_success "RSA key generation"
88 my_failure "RSA key generation"
95 if [ ! -s $DSA_KEY ]; then
96 echo -n "Generating SSH2 DSA host key: "
97 if $KEYGEN -q -t dsa -f $DSA_KEY -C '' -N '' >&/dev/null; then
99 chmod 644 $DSA_KEY.pub
100 my_success "DSA key generation"
103 my_failure "DSA key generation"
109 do_restart_sanity_check() {
112 if [ ! "$RETVAL" = 0 ]; then
113 my_failure "Configuration file or keys"
121 # Create keys if necessary
126 echo -n "Starting sshd: "
127 if [ ! -f $PID_FILE ] ; then
130 if [ "$RETVAL" = "0" ] ; then
131 my_success "sshd startup" "sshd"
132 touch /var/lock/subsys/sshd
134 my_failure "sshd startup" ""
140 echo -n "Shutting down sshd: "
141 if [ -f $PID_FILE ] ; then
144 [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/sshd
149 do_restart_sanity_check
155 if [ -f /var/lock/subsys/sshd ] ; then
156 do_restart_sanity_check
167 echo "Usage: sshd {start|stop|restart|status|condrestart}"