]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - etc/rc.d/sshd
Merge in all the changes that Mike Makonnen has been maintaining for a
[FreeBSD/FreeBSD.git] / etc / rc.d / sshd
1 #!/bin/sh
2 #
3 # $NetBSD: sshd,v 1.18 2002/04/29 08:23:34 lukem Exp $
4 # $FreeBSD$
5 #
6
7 # PROVIDE: sshd
8 # REQUIRE: LOGIN
9 # KEYWORD: FreeBSD NetBSD
10
11 . /etc/rc.subr
12
13 name="sshd"
14 rcvar=`set_rcvar`
15 command="/usr/sbin/${name}"
16 keygen_cmd="sshd_keygen"
17 start_precmd="sshd_precmd"
18 pidfile="/var/run/${name}.pid"
19 required_files="/etc/ssh/sshd_config"
20 extra_commands="keygen reload"
21
22 sshd_keygen()
23 {
24         (
25         umask 022
26
27         # Can't do anything if ssh is not installed
28         [ -x /usr/bin/ssh-keygen ] || {
29                 warn "/usr/bin/ssh-keygen does not exist."
30                 return 1
31         }
32
33         if [ -f /etc/ssh/ssh_host_key ]; then
34                 echo "You already have an RSA host key" \
35                     "in /etc/ssh/ssh_host_key"
36                 echo "Skipping protocol version 1 RSA Key Generation"
37         else
38                 /usr/bin/ssh-keygen -t rsa1 -b 1024 \
39                     -f /etc/ssh/ssh_host_key -N ''
40         fi
41
42         if [ -f /etc/ssh/ssh_host_dsa_key ]; then
43                 echo "You already have a DSA host key" \
44                     "in /etc/ssh/ssh_host_dsa_key"
45                 echo "Skipping protocol version 2 DSA Key Generation"
46         else
47                 /usr/bin/ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key -N ''
48         fi
49
50         if [ -f /etc/ssh/ssh_host_rsa_key ]; then
51                 echo "You already have a RSA host key" \
52                     "in /etc/ssh/ssh_host_rsa_key"
53                 echo "Skipping protocol version 2 RSA Key Generation"
54         else
55                 /usr/bin/ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N ''
56         fi
57         )
58 }
59
60 sshd_precmd()
61 {
62         if [ ! -f /etc/ssh/ssh_host_key -o \
63             ! -f /etc/ssh/ssh_host_dsa_key -o \
64             ! -f /etc/ssh/ssh_host_rsa_key ]; then
65                 run_rc_command keygen
66         fi
67 }
68
69 load_rc_config $name
70 run_rc_command "$1"