From 5cfec6f11d3b26b3cb0d0be1de6bed040870a2cf Mon Sep 17 00:00:00 2001 From: jwise Date: Mon, 31 Jul 2000 20:39:41 +0000 Subject: [PATCH] An sshd startup script for use with usr.bin/sshd. Installation is conditional on ${SSHDIST}, as with usr.bin/ssh itself. This script includes a `keygen' target for regenerating RSA and DSA host keys, and invokes this if these keys are not present when sshd is started up. --- etc/rc.d/Makefile | 6 +++++- etc/rc.d/sshd | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100755 etc/rc.d/sshd diff --git a/etc/rc.d/Makefile b/etc/rc.d/Makefile index bb6a662ab2d5..9b04bd92af7c 100755 --- a/etc/rc.d/Makefile +++ b/etc/rc.d/Makefile @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.8 2000/07/26 00:11:48 lukem Exp $ +# $NetBSD: Makefile,v 1.9 2000/07/31 20:39:41 jwise Exp $ FILES= DAEMON LOGIN NETWORK SERVERS accounting amd apmd bootparams \ bootconf.sh ccd cleartmp cron dhclient dhcpd dhcrelay dmesg fsck.sh \ @@ -12,6 +12,10 @@ FILES= DAEMON LOGIN NETWORK SERVERS accounting amd apmd bootparams \ FILESDIR= /etc/rc.d FILESMODE= ${BINMODE} +.if defined(SSHDIST) +FILES+= sshd +.endif + NOPROG= noprog .include diff --git a/etc/rc.d/sshd b/etc/rc.d/sshd new file mode 100755 index 000000000000..78c9105e3a9e --- /dev/null +++ b/etc/rc.d/sshd @@ -0,0 +1,46 @@ +#!/bin/sh +# + +# PROVIDE: ssh +# REQUIRE: NETWORK + +. /etc/rc.subr + +name="sshd" +command="/usr/sbin/sshd" +required_files="/etc/sshd.conf" + +extra_commands="keygen" + +sshd_keygen() { + if [ -f /etc/ssh_host_key ] + then + echo "You already have an RSA host key in /etc/ssh_host_key" + echo "Skipping RSA Key Generation" + else + umask 022 + /usr/bin/ssh-keygen -b 1024 -f /etc/ssh_host_key -N '' + fi + + if [ -f /etc/ssh_host_dsa_key ] + then + echo "You already have a DSA host key in /etc/ssh_host_dsa_key" + echo "Skipping RSA Key Generation" + else + umask 022 + /usr/bin/ssh-keygen -d -f /etc/ssh_host_dsa_key -N '' + fi +} + +start_precmd() { + if [ ! -f /etc/ssh_host_key -o ! -f /etc/ssh_host_dsa_key ] + then + /etc/rc.d/sshd keygen + fi +} + +keygen_cmd=sshd_keygen +start_precmd=start_precmd + +load_rc_config $name +run_rc_command "$1"