xref: /netbsd-src/etc/rc.d/sshd (revision 501cd18a74d52bfcca7d9e7e3b0d472bbc870558)
1#!/bin/sh
2#
3# $NetBSD: sshd,v 1.23 2014/10/19 16:33:01 christos Exp $
4#
5
6# PROVIDE: sshd
7# REQUIRE: LOGIN
8
9$_rc_subr_loaded . /etc/rc.subr
10
11name="sshd"
12rcvar=$name
13command="/usr/sbin/${name}"
14pidfile="/var/run/${name}.pid"
15required_files="/etc/ssh/sshd_config"
16extra_commands="keygen reload"
17
18sshd_keygen()
19{
20(
21	keygen="/usr/bin/ssh-keygen"
22	umask 022
23	while read type bits filename version name;  do
24		f="/etc/ssh/$filename"
25		if [ -f "$f" ]; then
26			echo "You already have an $name host key in $f"
27			echo "Skipping protocol version $version $name" \
28			    "Key Generation"
29		else
30			case "${bits}" in
31			-1)	bitarg=;;
32			0)	bitarg="${ssh_keygen_flags}";;
33			*)	bitarg="-b ${bits}";;
34			esac
35			"${keygen}" -t "${type}" ${bitarg} -f "${f}" -N ''
36		fi
37	done << _EOF
38rsa1	0	ssh_host_key		1	RSA
39dsa	1024	ssh_host_dsa_key	2	DSA
40ecdsa	521	ssh_host_ecdsa_key	1	ECDSA
41ed25519	-1	ssh_host_ed25519_key	1	ED25519
42rsa	0	ssh_host_rsa_key	2	RSA
43_EOF
44)
45}
46
47sshd_precmd()
48{
49	if [ ! -f /etc/ssh/ssh_host_key -o \
50	    ! -f /etc/ssh/ssh_host_dsa_key -o \
51	    ! -f /etc/ssh/ssh_host_ecdsa_key -o \
52	    ! -f /etc/ssh/ssh_host_ed25519_key -o \
53	    ! -f /etc/ssh/ssh_host_rsa_key ]; then
54		run_rc_command keygen
55	fi
56}
57
58keygen_cmd=sshd_keygen
59start_precmd=sshd_precmd
60
61load_rc_config $name
62run_rc_command "$1"
63