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.
11 # Source function library
12 . /etc/rc.d/init.d/functions
14 upstart_controlled --except init configtest
17 . /etc/sysconfig/network
20 PIDFILE=/var/run/sshd.pid
23 [ -f /etc/sysconfig/sshd ] && . /etc/sysconfig/sshd
25 # Check that networking is up.
26 if is_yes "${NETWORKING}"; then
27 if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status -a "$1" != init ]; then
28 msg_network_down "OpenSSH"
36 if [ -e $PIDFILE ]; then
37 for pid in $(cat $PIDFILE); do
38 echo "$SSHD_OOM_ADJUST" 2>/dev/null > /proc/$pid/oom_score_adj
45 /usr/sbin/sshd -t || exit 1
49 @@LIBEXECDIR@@/sshd-keygen
53 # Check if the service is already running?
54 if status --pidfile $PIDFILE sshd >/dev/null; then
55 msg_already_running "OpenSSH"
61 if [ ! -s /etc/ssh/ssh_host_key ]; then
62 msg_not_running "OpenSSH"
63 nls "No SSH host key found! You must run \"%s init\" first." "$0"
67 if is_yes "$IPV4_NETWORKING" && is_no "$IPV6_NETWORKING"; then
70 if is_yes "$IPV6_NETWORKING" && is_no "$IPV4_NETWORKING"; then
74 msg_starting "OpenSSH"
75 daemon --pidfile $PIDFILE /usr/sbin/sshd $OPTIONS
78 [ $RETVAL -eq 0 ] && touch /var/lock/subsys/sshd
82 if [ ! -f /var/lock/subsys/sshd ]; then
83 msg_not_running "OpenSSH"
87 msg_stopping "OpenSSH"
88 # we use start-stop-daemon to stop sshd, as it is unacceptable for such
89 # critical service as sshd to kill it by procname, but unfortunately
90 # rc-scripts does not provide way to kill *only* by pidfile
91 start-stop-daemon --stop --quiet --pidfile $PIDFILE && ok || fail
92 rm -f /var/lock/subsys/sshd >/dev/null 2>&1
96 if [ ! -f /var/lock/subsys/sshd ]; then
97 msg_not_running "OpenSSH"
103 msg_reloading "OpenSSH"
109 if [ ! -f /var/lock/subsys/sshd ]; then
110 msg_not_running "OpenSSH"
121 # See how we were called.
144 nls "Now the SSH host key will be generated. Please note, that if you"
145 nls "will use password for the key, you will need to type it on each"
150 status --pidfile $PIDFILE sshd
154 msg_usage "$0 {start|stop|restart|try-restart|reload|force-reload|configtest|init|status}"