3 # sshd sshd (secure shell daemon)
7 # description: sshd (secure shell daemon) is a server part of the ssh suite. \
8 # Ssh can be used for remote login, remote file copying, TCP port \
9 # forwarding etc. Ssh offers strong encryption and authentication.
12 # Source function library
13 . /etc/rc.d/init.d/functions
16 . /etc/sysconfig/network
19 [ -f /etc/sysconfig/sshd ] && . /etc/sysconfig/sshd
21 # Check that networking is up.
22 if is_yes "${NETWORKING}"; then
23 if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status -a "$1" != init ]; then
24 msg_network_down OpenSSH
32 /usr/sbin/sshd -t || exit 1
36 # generate new keys with empty passwords if they do not exist
37 if [ ! -f /etc/ssh/ssh_host_key -o ! -s /etc/ssh/ssh_host_key ]; then
38 /usr/bin/ssh-keygen -t rsa1 -f /etc/ssh/ssh_host_key -N '' 1>&2
39 chmod 600 /etc/ssh/ssh_host_key
40 [ -x /sbin/restorecon ] && /sbin/restorecon /etc/ssh/ssh_host_key || :
42 if [ ! -f /etc/ssh/ssh_host_rsa_key -o ! -s /etc/ssh/ssh_host_rsa_key ]; then
43 /usr/bin/ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N '' 1>&2
44 chmod 600 /etc/ssh/ssh_host_rsa_key
45 [ -x /sbin/restorecon ] && /sbin/restorecon /etc/ssh/ssh_host_rsa_key || :
47 if [ ! -f /etc/ssh/ssh_host_dsa_key -o ! -s /etc/ssh/ssh_host_dsa_key ]; then
48 /usr/bin/ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key -N '' 1>&2
49 chmod 600 /etc/ssh/ssh_host_dsa_key
50 [ -x /sbin/restorecon ] && /sbin/restorecon /etc/ssh/ssh_host_dsa_key || :
55 if [ ! -f /etc/ssh/ssh_host_key ]; then
56 msg_not_running OpenSSH
57 nls "No SSH host key found! You must run \"%s init\" first." "$0"
61 # Check if the service is already running?
62 if [ ! -f /var/lock/subsys/sshd ]; then
66 [ $RETVAL -eq 0 ] && touch /var/lock/subsys/sshd
68 msg_already_running OpenSSH
73 if [ -f /var/lock/subsys/sshd ]; then
75 # we use start-stop-daemon to stop sshd, as it is unacceptable for such
76 # critical service as sshd to kill it by procname, but unfortunately
77 # rc-scripts does not provide way to kill *only* by pidfile
78 start-stop-daemon --stop --quiet --pidfile /var/run/sshd.pid && ok || fail
79 rm -f /var/lock/subsys/sshd >/dev/null 2>&1
81 msg_not_running OpenSSH
86 # See how we were called.
104 nls "Now the SSH host key will be generated. Please note, that if you"
105 nls "will use password for the key, you will need to type it on each"
107 /usr/bin/ssh-keygen -t rsa1 -f /etc/ssh/ssh_host_key
108 [ -x /sbin/restorecon ] && /sbin/restorecon /etc/ssh/ssh_host_key || :
109 chmod 600 /etc/ssh/ssh_host_key
110 /usr/bin/ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
111 [ -x /sbin/restorecon ] && /sbin/restorecon /etc/ssh/ssh_host_rsa_key || :
112 chmod 600 /etc/ssh/ssh_host_rsa_key
113 /usr/bin/ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key
114 chmod 600 /etc/ssh/ssh_host_dsa_key
115 [ -x /sbin/restorecon ] && /sbin/restorecon /etc/ssh/ssh_host_dsa_key || :
119 if [ -f /var/lock/subsys/sshd ]; then
121 msg_reloading OpenSSH
125 msg_not_running OpenSSH
130 msg_usage "$0 {start|stop|init|restart|reload|force-reload|status}"