]> git.pld-linux.org Git - packages/openssh.git/blame - opensshd.init
- add http://www.imasy.or.jp/~gotoh/ssh/connect.html
[packages/openssh.git] / opensshd.init
CommitLineData
cf3b46d6
AF
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
69fe0cc7 18SERVICE_LIMITS_HARD="-u unlimited"
e84d8e9f 19SERVICE_LIMITS_SOFT="-u unlimited -c 0"
69fe0cc7 20
cf3b46d6
AF
21# Get service config
22[ -f /etc/sysconfig/sshd ] && . /etc/sysconfig/sshd
23
24# Check that networking is up.
7d58fbb0 25if is_yes "${NETWORKING}"; then
224aaee1 26 if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status -a "$1" != init ]; then
7d58fbb0 27 msg_network_down OpenSSH
28 exit 1
29 fi
30else
31 exit 0
cf3b46d6 32fi
cbd44157 33
bff0c7f8 34RETVAL=0
cf3b46d6
AF
35# See how we were called.
36case "$1" in
37 start)
3c573fc0 38 # generate new keys with empty passwords if they do not exist
39 if [ ! -f /etc/ssh/ssh_host_key -o ! -s /etc/ssh/ssh_host_key ]; then
7d58fbb0 40 /usr/bin/ssh-keygen -t rsa1 -f /etc/ssh/ssh_host_key -N '' 1>&2
41 chmod 600 /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
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
3c573fc0 50 fi
51
01d1f289 52 if [ ! -f /etc/ssh/ssh_host_key ]; then
9ceb608e 53 msg_not_running OpenSSH
7d58fbb0 54 nls "No SSH host key found! You must run \"%s init\" first." "$0"
01d1f289 55 exit 1
56 fi
3c573fc0 57
58 # Check if the service is already running?
cf3b46d6 59 if [ ! -f /var/lock/subsys/sshd ]; then
cbd44157 60 msg_starting OpenSSH
2a63b97e 61 daemon /usr/sbin/sshd
cbd44157 62 RETVAL=$?
63 [ $RETVAL -eq 0 ] && touch /var/lock/subsys/sshd
cf3b46d6 64 else
9ceb608e 65 msg_already_running OpenSSH
cf3b46d6 66 fi
cf3b46d6
AF
67 ;;
68 stop)
7d58fbb0 69 if [ -f /var/lock/subsys/sshd ]; then
cbd44157 70 msg_stopping OpenSSH
71 killproc sshd
72 rm -f /var/run/sshd.pid /var/lock/subsys/sshd >/dev/null 2>&1
73 else
9ceb608e 74 msg_not_running OpenSSH
cbd44157 75 fi
cf3b46d6 76 ;;
cbd44157 77 restart)
cf3b46d6
AF
78 $0 stop
79 $0 start
bff0c7f8 80 exit $?
cf3b46d6
AF
81 ;;
82 status)
83 status sshd
cbd44157 84 exit $?
cf3b46d6 85 ;;
01d1f289 86 init)
0d883194 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."
ff7a4dcc 90 /usr/bin/ssh-keygen -t rsa1 -f /etc/ssh/ssh_host_key
cf14c2df 91 chmod 600 /etc/ssh/ssh_host_key
ff7a4dcc
AM
92 /usr/bin/ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
93 chmod 600 /etc/ssh/ssh_host_rsa_key
7d58fbb0 94 /usr/bin/ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key
cf14c2df 95 chmod 600 /etc/ssh/ssh_host_dsa_key
01d1f289 96 exit $?
36f63877 97 ;;
bff0c7f8 98 reload|force-reload)
0d883194 99 if [ -f /var/lock/subsys/sshd ]; then
100 msg_reloading OpenSSH
0d883194 101 killproc sshd -HUP
102 RETVAL=$?
0d883194 103 else
bff0c7f8 104 msg_not_running OpenSSH >&2
105 exit 7
0d883194 106 fi
36f63877 107 ;;
cf3b46d6 108 *)
bff0c7f8 109 msg_usage "$0 {start|stop|init|restart|reload|force-reload|status}"
110 exit 3
cf3b46d6
AF
111esac
112
cbd44157 113exit $RETVAL
This page took 0.058752 seconds and 4 git commands to generate.