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