]> git.pld-linux.org Git - packages/openssh.git/blob - opensshd.init
- enhanced openssh-chroot.patch with UseChroot configuration option
[packages/openssh.git] / opensshd.init
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 SERVICE_LIMITS="-u unlimited -Sc 0"
19
20 # Get service config
21 [ -f /etc/sysconfig/sshd ] && . /etc/sysconfig/sshd
22
23 # Check that networking is up.
24 if is_yes "${NETWORKING}"; then
25         if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status -a "$1" != init ]; then
26                 msg_network_down OpenSSH
27                 exit 1
28         fi
29 else
30         exit 0
31 fi
32                         
33 RETVAL=0
34 # See how we were called.
35 case "$1" in
36   start)
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
39                 /usr/bin/ssh-keygen -t rsa1 -f /etc/ssh/ssh_host_key -N '' 1>&2
40                 chmod 600 /etc/ssh/ssh_host_key
41         fi
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         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         fi
50
51         if [ ! -f /etc/ssh/ssh_host_key ]; then
52                 msg_not_running OpenSSH
53                 nls "No SSH host key found! You must run \"%s init\" first." "$0"
54                 exit 1
55         fi
56
57         # Check if the service is already running?
58         if [ ! -f /var/lock/subsys/sshd ]; then
59                 msg_starting OpenSSH
60                 daemon /usr/sbin/sshd 
61                 RETVAL=$?
62                 [ $RETVAL -eq 0 ] && touch /var/lock/subsys/sshd                
63         else
64                 msg_already_running OpenSSH
65         fi
66         ;;
67   stop)
68         if [ -f /var/lock/subsys/sshd ]; then
69                 msg_stopping OpenSSH
70                 killproc sshd
71                 rm -f /var/run/sshd.pid /var/lock/subsys/sshd >/dev/null 2>&1
72         else
73                 msg_not_running OpenSSH
74         fi      
75         ;;
76   restart)
77         $0 stop
78         $0 start
79         exit $?
80         ;;
81   status)
82         status sshd
83         exit $?
84         ;;
85   init)
86         nls "Now the SSH host key will be generated. Please note, that if you"
87         nls "will use password for the key, you will need to type it on each"
88         nls "reboot."
89         /usr/bin/ssh-keygen -t rsa1 -f /etc/ssh/ssh_host_key
90         chmod 600 /etc/ssh/ssh_host_key
91         /usr/bin/ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
92         chmod 600 /etc/ssh/ssh_host_rsa_key
93         /usr/bin/ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key
94         chmod 600 /etc/ssh/ssh_host_dsa_key
95         exit $?
96         ;;
97   reload|force-reload)
98         if [ -f /var/lock/subsys/sshd ]; then
99                 msg_reloading OpenSSH
100                 killproc sshd -HUP
101                 RETVAL=$?
102         else
103                 msg_not_running OpenSSH >&2
104                 exit 7
105         fi
106         ;;
107   *)
108         msg_usage "$0 {start|stop|init|restart|reload|force-reload|status}"
109         exit 3
110 esac
111
112 exit $RETVAL
This page took 0.037206 seconds and 3 git commands to generate.