]>
Commit | Line | Data |
---|---|---|
cf3b46d6 AF |
1 | #!/bin/sh |
2 | # | |
3 | # sshd sshd (secure shell daemon) | |
4 | # | |
5 | # chkconfig: 345 55 45 | |
6 | # | |
4a9f24b4 | 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 \ | |
cf3b46d6 AF |
9 | # forwarding etc. Ssh offers strong encryption and authentication. |
10 | ||
11 | ||
12 | # Source function library | |
13 | . /etc/rc.d/init.d/functions | |
14 | ||
15 | # Get network config | |
16 | . /etc/sysconfig/network | |
17 | ||
18 | # Get service config | |
19 | [ -f /etc/sysconfig/sshd ] && . /etc/sysconfig/sshd | |
20 | ||
21 | # Check that networking is up. | |
7d58fbb0 | 22 | if is_yes "${NETWORKING}"; then |
224aaee1 | 23 | if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status -a "$1" != init ]; then |
7d58fbb0 | 24 | msg_network_down OpenSSH |
25 | exit 1 | |
26 | fi | |
27 | else | |
28 | exit 0 | |
cf3b46d6 | 29 | fi |
a1c37c17 | 30 | |
945a8076 ER |
31 | checkconfig() { |
32 | /usr/sbin/sshd -t || exit 1 | |
33 | } | |
34 | ||
b10eed65 | 35 | start() { |
3c573fc0 | 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 | |
7d58fbb0 | 38 | /usr/bin/ssh-keygen -t rsa1 -f /etc/ssh/ssh_host_key -N '' 1>&2 |
39 | chmod 600 /etc/ssh/ssh_host_key | |
b79cf855 | 40 | [ -x /sbin/restorecon ] && /sbin/restorecon /etc/ssh/ssh_host_key || : |
3c573fc0 | 41 | fi |
42 | if [ ! -f /etc/ssh/ssh_host_rsa_key -o ! -s /etc/ssh/ssh_host_rsa_key ]; then | |
7d58fbb0 | 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 | |
b79cf855 | 45 | [ -x /sbin/restorecon ] && /sbin/restorecon /etc/ssh/ssh_host_rsa_key || : |
3c573fc0 | 46 | fi |
47 | if [ ! -f /etc/ssh/ssh_host_dsa_key -o ! -s /etc/ssh/ssh_host_dsa_key ]; then | |
7d58fbb0 | 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 | |
b79cf855 | 50 | [ -x /sbin/restorecon ] && /sbin/restorecon /etc/ssh/ssh_host_dsa_key || : |
3c573fc0 | 51 | fi |
52 | ||
945a8076 ER |
53 | checkconfig |
54 | ||
01d1f289 | 55 | if [ ! -f /etc/ssh/ssh_host_key ]; then |
9ceb608e | 56 | msg_not_running OpenSSH |
7d58fbb0 | 57 | nls "No SSH host key found! You must run \"%s init\" first." "$0" |
01d1f289 | 58 | exit 1 |
59 | fi | |
3c573fc0 | 60 | |
61 | # Check if the service is already running? | |
cf3b46d6 | 62 | if [ ! -f /var/lock/subsys/sshd ]; then |
cbd44157 | 63 | msg_starting OpenSSH |
a1c37c17 | 64 | daemon /usr/sbin/sshd |
cbd44157 | 65 | RETVAL=$? |
a1c37c17 | 66 | [ $RETVAL -eq 0 ] && touch /var/lock/subsys/sshd |
cf3b46d6 | 67 | else |
9ceb608e | 68 | msg_already_running OpenSSH |
cf3b46d6 | 69 | fi |
b10eed65 ER |
70 | } |
71 | ||
72 | stop() { | |
7d58fbb0 | 73 | if [ -f /var/lock/subsys/sshd ]; then |
cbd44157 | 74 | msg_stopping OpenSSH |
3007cef9 ER |
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 | |
cbd44157 | 80 | else |
9ceb608e | 81 | msg_not_running OpenSSH |
a1c37c17 | 82 | fi |
b10eed65 ER |
83 | } |
84 | ||
85 | RETVAL=0 | |
86 | # See how we were called. | |
87 | case "$1" in | |
88 | start) | |
89 | start | |
90 | ;; | |
91 | stop) | |
92 | stop | |
cf3b46d6 | 93 | ;; |
cbd44157 | 94 | restart) |
945a8076 | 95 | checkconfig |
b10eed65 ER |
96 | stop |
97 | start | |
cf3b46d6 AF |
98 | ;; |
99 | status) | |
100 | status sshd | |
cbd44157 | 101 | exit $? |
cf3b46d6 | 102 | ;; |
01d1f289 | 103 | init) |
0d883194 | 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" | |
106 | nls "reboot." | |
ff7a4dcc | 107 | /usr/bin/ssh-keygen -t rsa1 -f /etc/ssh/ssh_host_key |
b79cf855 | 108 | [ -x /sbin/restorecon ] && /sbin/restorecon /etc/ssh/ssh_host_key || : |
cf14c2df | 109 | chmod 600 /etc/ssh/ssh_host_key |
ff7a4dcc | 110 | /usr/bin/ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key |
b79cf855 | 111 | [ -x /sbin/restorecon ] && /sbin/restorecon /etc/ssh/ssh_host_rsa_key || : |
ff7a4dcc | 112 | chmod 600 /etc/ssh/ssh_host_rsa_key |
7d58fbb0 | 113 | /usr/bin/ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key |
cf14c2df | 114 | chmod 600 /etc/ssh/ssh_host_dsa_key |
b79cf855 | 115 | [ -x /sbin/restorecon ] && /sbin/restorecon /etc/ssh/ssh_host_dsa_key || : |
01d1f289 | 116 | exit $? |
36f63877 | 117 | ;; |
bff0c7f8 | 118 | reload|force-reload) |
0d883194 | 119 | if [ -f /var/lock/subsys/sshd ]; then |
d1017959 | 120 | checkconfig |
0d883194 | 121 | msg_reloading OpenSSH |
0d883194 | 122 | killproc sshd -HUP |
123 | RETVAL=$? | |
0d883194 | 124 | else |
bbbbe539 | 125 | msg_not_running OpenSSH |
bff0c7f8 | 126 | exit 7 |
0d883194 | 127 | fi |
36f63877 | 128 | ;; |
cf3b46d6 | 129 | *) |
bff0c7f8 | 130 | msg_usage "$0 {start|stop|init|restart|reload|force-reload|status}" |
131 | exit 3 | |
cf3b46d6 AF |
132 | esac |
133 | ||
cbd44157 | 134 | exit $RETVAL |