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
20 # Some functions to make the below more readable
21 KEYGEN=/usr/bin/ssh-keygen
22 RSA1_KEY=/etc/ssh/ssh_host_key
23 RSA_KEY=/etc/ssh/ssh_host_rsa_key
24 DSA_KEY=/etc/ssh/ssh_host_dsa_key
25 PID_FILE=/var/run/sshd.pid
27 if ! test -f $RSA1_KEY ; then
28 echo -n "Generating SSH1 RSA host key: "
29 if $KEYGEN -q -t rsa1 -f $RSA1_KEY -C '' -N '' >&/dev/null; then
30 success "RSA1 key generation"
33 failure "RSA1 key generation"
40 if ! test -f $RSA_KEY ; then
41 echo -n "Generating SSH2 RSA host key: "
42 if $KEYGEN -q -t rsa -f $RSA_KEY -C '' -N '' >&/dev/null; then
43 success "RSA key generation"
46 failure "RSA key generation"
53 if ! test -f $DSA_KEY ; then
54 echo -n "Generating SSH2 DSA host key: "
55 if $KEYGEN -q -t dsa -f $DSA_KEY -C '' -N '' >&/dev/null; then
56 success "DSA key generation"
59 failure "DSA key generation"
68 # Create keys if necessary
73 echo -n "Starting sshd: "
74 if [ ! -f $PID_FILE ] ; then
77 if [ "$RETVAL" = "0" ] ; then
78 success "sshd startup"
79 touch /var/lock/subsys/sshd
81 failure "sshd startup"
87 echo -n "Shutting down sshd: "
88 if [ -f $PID_FILE ] ; then
91 [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/sshd
101 if [ -f /var/lock/subsys/sshd ] ; then
112 echo "Usage: sshd {start|stop|restart|status|condrestart}"