sshd revision 1.31
11.1Slukem#!/bin/sh 21.1Slukem# 31.31Smartin# $NetBSD: sshd,v 1.31 2021/09/26 10:53:20 martin Exp $ 41.5Sjwise# 51.1Slukem 61.6Slukem# PROVIDE: sshd 71.6Slukem# REQUIRE: LOGIN 81.1Slukem 91.20Smycroft$_rc_subr_loaded . /etc/rc.subr 101.1Slukem 111.1Slukemname="sshd" 121.8Slukemrcvar=$name 131.6Slukemcommand="/usr/sbin/${name}" 141.7Slukempidfile="/var/run/${name}.pid" 151.18Slukemrequired_files="/etc/ssh/sshd_config" 161.31Smartinextra_commands="keygen keyregen reload" 171.31Smartin 181.31Smartinsshd_motd_unsafe_keys_warning() 191.31Smartin{ 201.31Smartin( 211.31Smartin umask 022 221.31Smartin T=/etc/_motd 231.31Smartin sed -E '/^-- UNSAFE KEYS WARNING:/,$d' < /etc/motd > $T 241.31Smartin if [ $( sysctl -n kern.entropy.needed ) -ne 0 ]; then 251.31Smartin cat >> $T << _EOF 261.31Smartin-- UNSAFE KEYS WARNING: 271.31Smartin 281.31Smartin The ssh host keys on this machine have been generated with 291.31Smartin not enough entropy configured, so may be predictable. 301.31Smartin 311.31Smartin To fix, follow the "Adding entropy" section in the entropy(7) 321.31Smartin man page and after this machine has enough entropy, re-generate 331.31Smartin the ssh host keys by running: 341.31Smartin 351.31Smartin sh /etc/rc.d/sshd keyregen 361.31Smartin_EOF 371.31Smartin fi 381.31Smartin cmp -s $T /etc/motd || cp $T /etc/motd 391.31Smartin rm -f $T 401.31Smartin) 411.31Smartin} 421.3Sjwise 431.6Slukemsshd_keygen() 441.6Slukem{ 451.23Schristos( 461.23Schristos keygen="/usr/bin/ssh-keygen" 471.11Slukem umask 022 481.30Schristos while read type bits filename; do 491.23Schristos f="/etc/ssh/$filename" 501.31Smartin if [ "$1" != "force" ] && [ -f "$f" ]; then 511.27Schristos continue 521.23Schristos fi 531.31Smartin rm -f "$f" 541.27Schristos case "${bits}" in 551.27Schristos -1) bitarg=;; 561.27Schristos 0) bitarg="${ssh_keygen_flags}";; 571.27Schristos *) bitarg="-b ${bits}";; 581.27Schristos esac 591.28Sjmcneill "${keygen}" -t "${type}" ${bitarg} -f "${f}" -N '' -q && \ 601.28Sjmcneill printf "ssh-keygen: " && "${keygen}" -f "${f}" -l 611.23Schristos done << _EOF 621.30Schristosdsa 1024 ssh_host_dsa_key 631.30Schristosecdsa 521 ssh_host_ecdsa_key 641.30Schristosed25519 -1 ssh_host_ed25519_key 651.30Schristosrsa 0 ssh_host_rsa_key 661.23Schristos_EOF 671.23Schristos) 681.31Smartin sshd_motd_unsafe_keys_warning 691.3Sjwise} 701.3Sjwise 711.6Slukemsshd_precmd() 721.6Slukem{ 731.27Schristos run_rc_command keygen 741.3Sjwise} 751.3Sjwise 761.3Sjwisekeygen_cmd=sshd_keygen 771.31Smartinkeyregen_cmd="sshd_keygen force" 781.5Sjwisestart_precmd=sshd_precmd 791.3Sjwise 801.3Sjwiseload_rc_config $name 811.3Sjwiserun_rc_command "$1" 82