Skip to content

Instantly share code, notes, and snippets.

@lwhsu
Created May 16, 2024 07:50
Show Gist options
  • Save lwhsu/aa042311d3924d62b40cce455aadccd6 to your computer and use it in GitHub Desktop.
Save lwhsu/aa042311d3924d62b40cce455aadccd6 to your computer and use it in GitHub Desktop.
diff --git a/libexec/rc/rc.d/sshd b/libexec/rc/rc.d/sshd
index 63113fd9ee74..faf619a6639c 100755
--- a/libexec/rc/rc.d/sshd
+++ b/libexec/rc/rc.d/sshd
@@ -56,6 +56,37 @@ sshd_keygen_alg()
echo "Generating $ALG host key."
/usr/bin/ssh-keygen -q -t $alg -f "$keyfile" -N ""
+}
+
+sshd_showfp_alg()
+{
+ local alg=$1
+ local ALG="$(echo $alg | tr a-z A-Z)"
+ local keyfile
+
+ if ! checkyesno "sshd_${alg}_enable" ; then
+ return 0
+ fi
+
+ case $alg in
+ rsa|dsa|ecdsa|ed25519)
+ keyfile="/etc/ssh/ssh_host_${alg}_key"
+ ;;
+ *)
+ return 1
+ ;;
+ esac
+
+ if [ ! -f "${keyfile}" ] ; then
+ warn "$ALG host key does not exist."
+ return 1
+ fi
+
+ if [ ! -x /usr/bin/ssh-keygen ] ; then
+ warn "/usr/bin/ssh-keygen does not exist."
+ return 1
+ fi
+
/usr/bin/ssh-keygen -l -f "$keyfile.pub"
}
@@ -73,10 +104,19 @@ sshd_configtest()
eval ${command} ${sshd_flags} -t
}
+sshd_showfp()
+{
+ sshd_showfp_alg rsa
+ sshd_showfp_alg dsa
+ sshd_showfp_alg ecdsa
+ sshd_showfp_alg ed25519
+}
+
sshd_precmd()
{
run_rc_command keygen
run_rc_command configtest
+ run_rc_command showfp
}
load_rc_config $name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment