Resync patch with contrib.
[dragonfly.git] / etc / rc.d / sshd
blobed24834538e2cfbd1542a15ffe3249f0f0885be1
1 #!/bin/sh
3 # $NetBSD: sshd,v 1.18 2002/04/29 08:23:34 lukem Exp $
4 # $FreeBSD: src/etc/rc.d/sshd,v 1.3 2003/07/13 01:49:07 mtm Exp $
5 # $DragonFly: src/etc/rc.d/sshd,v 1.3 2005/11/19 21:47:32 swildner Exp $
8 # PROVIDE: sshd
9 # REQUIRE: LOGIN
11 . /etc/rc.subr
13 name="sshd"
14 rcvar=`set_rcvar`
15 keygen_cmd="sshd_keygen"
16 start_precmd="sshd_precmd"
17 pidfile="/var/run/${name}.pid"
18 extra_commands="keygen reload"
20 sshd_keygen()
23 umask 022
25 # Can't do anything if ssh is not installed
26 [ -x /usr/bin/ssh-keygen ] || {
27 warn "/usr/bin/ssh-keygen does not exist."
28 return 1
31 if [ -f /etc/ssh/ssh_host_key ]; then
32 echo "You already have an RSA host key" \
33 "in /etc/ssh/ssh_host_key"
34 echo "Skipping protocol version 1 RSA Key Generation"
35 else
36 /usr/bin/ssh-keygen -t rsa1 -b 1024 \
37 -f /etc/ssh/ssh_host_key -N ''
40 if [ -f /etc/ssh/ssh_host_dsa_key ]; then
41 echo "You already have a DSA host key" \
42 "in /etc/ssh/ssh_host_dsa_key"
43 echo "Skipping protocol version 2 DSA Key Generation"
44 else
45 /usr/bin/ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key -N ''
48 if [ -f /etc/ssh/ssh_host_rsa_key ]; then
49 echo "You already have a RSA host key" \
50 "in /etc/ssh/ssh_host_rsa_key"
51 echo "Skipping protocol version 2 RSA Key Generation"
52 else
53 /usr/bin/ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N ''
58 sshd_precmd()
60 if [ ! -f /etc/ssh/ssh_host_key -o \
61 ! -f /etc/ssh/ssh_host_dsa_key -o \
62 ! -f /etc/ssh/ssh_host_rsa_key ]; then
63 run_rc_command keygen
67 load_rc_config $name
68 run_rc_command "$1"