1#!/bin/sh 2# 3# $NetBSD: sshd,v 1.20 2004/08/13 18:08:03 mycroft 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 umask 022 22 if [ -f /etc/ssh/ssh_host_key ]; then 23 echo "You already have an RSA host key" \ 24 "in /etc/ssh/ssh_host_key" 25 echo "Skipping protocol version 1 RSA Key Generation" 26 else 27 /usr/bin/ssh-keygen -t rsa1 ${ssh_keygen_flags} \ 28 -f /etc/ssh/ssh_host_key -N '' 29 fi 30 31 if [ -f /etc/ssh/ssh_host_dsa_key ]; then 32 echo "You already have a DSA host key" \ 33 "in /etc/ssh/ssh_host_dsa_key" 34 echo "Skipping protocol version 2 DSA Key Generation" 35 else 36 /usr/bin/ssh-keygen -t dsa ${ssh_keygen_flags} \ 37 -f /etc/ssh/ssh_host_dsa_key -N '' 38 fi 39 40 if [ -f /etc/ssh/ssh_host_ecdsa_key ]; then 41 echo "You already have a ECDSA host key" \ 42 "in /etc/ssh/ssh_host_ecdsa_key" 43 echo "Skipping protocol version 1 ECDSA Key Generation" 44 else 45 /usr/bin/ssh-keygen -t ecdsa -b 521 \ 46 -f /etc/ssh/ssh_host_ecdsa_key -N '' 47 fi 48 49 if [ -f /etc/ssh/ssh_host_rsa_key ]; then 50 echo "You already have a RSA host key" \ 51 "in /etc/ssh/ssh_host_rsa_key" 52 echo "Skipping protocol version 2 RSA Key Generation" 53 else 54 /usr/bin/ssh-keygen -t rsa ${ssh_keygen_flags} \ 55 -f /etc/ssh/ssh_host_rsa_key -N '' 56 fi 57 ) 58} 59 60sshd_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_ecdsa_key -o \ 65 ! -f /etc/ssh/ssh_host_rsa_key ]; then 66 run_rc_command keygen 67 fi 68} 69 70keygen_cmd=sshd_keygen 71start_precmd=sshd_precmd 72 73load_rc_config $name 74run_rc_command "$1" 75