]>
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 | ||
6e0511be | 18 | SERVICE_LIMITS="-u unlimited -Sc 0" |
69fe0cc7 | 19 | |
cf3b46d6 AF |
20 | # Get service config |
21 | [ -f /etc/sysconfig/sshd ] && . /etc/sysconfig/sshd | |
22 | ||
23 | # Check that networking is up. | |
7d58fbb0 | 24 | if is_yes "${NETWORKING}"; then |
224aaee1 | 25 | if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status -a "$1" != init ]; then |
7d58fbb0 | 26 | msg_network_down OpenSSH |
27 | exit 1 | |
28 | fi | |
29 | else | |
30 | exit 0 | |
cf3b46d6 | 31 | fi |
cbd44157 | 32 | |
bff0c7f8 | 33 | RETVAL=0 |
cf3b46d6 AF |
34 | # See how we were called. |
35 | case "$1" in | |
36 | start) | |
3c573fc0 | 37 | # generate new keys with empty passwords if they do not exist |
38 | if [ ! -f /etc/ssh/ssh_host_key -o ! -s /etc/ssh/ssh_host_key ]; then | |
7d58fbb0 | 39 | /usr/bin/ssh-keygen -t rsa1 -f /etc/ssh/ssh_host_key -N '' 1>&2 |
40 | chmod 600 /etc/ssh/ssh_host_key | |
b79cf855 | 41 | [ -x /sbin/restorecon ] && /sbin/restorecon /etc/ssh/ssh_host_key || : |
3c573fc0 | 42 | fi |
43 | if [ ! -f /etc/ssh/ssh_host_rsa_key -o ! -s /etc/ssh/ssh_host_rsa_key ]; then | |
7d58fbb0 | 44 | /usr/bin/ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N '' 1>&2 |
45 | chmod 600 /etc/ssh/ssh_host_rsa_key | |
b79cf855 | 46 | [ -x /sbin/restorecon ] && /sbin/restorecon /etc/ssh/ssh_host_rsa_key || : |
3c573fc0 | 47 | fi |
48 | if [ ! -f /etc/ssh/ssh_host_dsa_key -o ! -s /etc/ssh/ssh_host_dsa_key ]; then | |
7d58fbb0 | 49 | /usr/bin/ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key -N '' 1>&2 |
50 | chmod 600 /etc/ssh/ssh_host_dsa_key | |
b79cf855 | 51 | [ -x /sbin/restorecon ] && /sbin/restorecon /etc/ssh/ssh_host_dsa_key || : |
3c573fc0 | 52 | fi |
53 | ||
01d1f289 | 54 | if [ ! -f /etc/ssh/ssh_host_key ]; then |
9ceb608e | 55 | msg_not_running OpenSSH |
7d58fbb0 | 56 | nls "No SSH host key found! You must run \"%s init\" first." "$0" |
01d1f289 | 57 | exit 1 |
58 | fi | |
3c573fc0 | 59 | |
60 | # Check if the service is already running? | |
cf3b46d6 | 61 | if [ ! -f /var/lock/subsys/sshd ]; then |
cbd44157 | 62 | msg_starting OpenSSH |
2a63b97e | 63 | daemon /usr/sbin/sshd |
cbd44157 | 64 | RETVAL=$? |
65 | [ $RETVAL -eq 0 ] && touch /var/lock/subsys/sshd | |
cf3b46d6 | 66 | else |
9ceb608e | 67 | msg_already_running OpenSSH |
cf3b46d6 | 68 | fi |
cf3b46d6 AF |
69 | ;; |
70 | stop) | |
7d58fbb0 | 71 | if [ -f /var/lock/subsys/sshd ]; then |
cbd44157 | 72 | msg_stopping OpenSSH |
73 | killproc sshd | |
74 | rm -f /var/run/sshd.pid /var/lock/subsys/sshd >/dev/null 2>&1 | |
75 | else | |
9ceb608e | 76 | msg_not_running OpenSSH |
cbd44157 | 77 | fi |
cf3b46d6 | 78 | ;; |
cbd44157 | 79 | restart) |
cf3b46d6 AF |
80 | $0 stop |
81 | $0 start | |
bff0c7f8 | 82 | exit $? |
cf3b46d6 AF |
83 | ;; |
84 | status) | |
85 | status sshd | |
cbd44157 | 86 | exit $? |
cf3b46d6 | 87 | ;; |
01d1f289 | 88 | init) |
0d883194 | 89 | nls "Now the SSH host key will be generated. Please note, that if you" |
90 | nls "will use password for the key, you will need to type it on each" | |
91 | nls "reboot." | |
ff7a4dcc | 92 | /usr/bin/ssh-keygen -t rsa1 -f /etc/ssh/ssh_host_key |
b79cf855 | 93 | [ -x /sbin/restorecon ] && /sbin/restorecon /etc/ssh/ssh_host_key || : |
cf14c2df | 94 | chmod 600 /etc/ssh/ssh_host_key |
ff7a4dcc | 95 | /usr/bin/ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key |
b79cf855 | 96 | [ -x /sbin/restorecon ] && /sbin/restorecon /etc/ssh/ssh_host_rsa_key || : |
ff7a4dcc | 97 | chmod 600 /etc/ssh/ssh_host_rsa_key |
7d58fbb0 | 98 | /usr/bin/ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key |
cf14c2df | 99 | chmod 600 /etc/ssh/ssh_host_dsa_key |
b79cf855 | 100 | [ -x /sbin/restorecon ] && /sbin/restorecon /etc/ssh/ssh_host_dsa_key || : |
01d1f289 | 101 | exit $? |
36f63877 | 102 | ;; |
bff0c7f8 | 103 | reload|force-reload) |
0d883194 | 104 | if [ -f /var/lock/subsys/sshd ]; then |
105 | msg_reloading OpenSSH | |
0d883194 | 106 | killproc sshd -HUP |
107 | RETVAL=$? | |
0d883194 | 108 | else |
bff0c7f8 | 109 | msg_not_running OpenSSH >&2 |
110 | exit 7 | |
0d883194 | 111 | fi |
36f63877 | 112 | ;; |
cf3b46d6 | 113 | *) |
bff0c7f8 | 114 | msg_usage "$0 {start|stop|init|restart|reload|force-reload|status}" |
115 | exit 3 | |
cf3b46d6 AF |
116 | esac |
117 | ||
cbd44157 | 118 | exit $RETVAL |