bootstrap-vz/bootstrapvz/common/assets/ssh-generate-hostkeys

24 lines
746 B
Text
Raw Normal View History

#!/bin/sh
# This file was created by bootstrap-vz.
# See https://github.com/andsens/bootstrap-vz/blob/master/LICENSE for
# legal notices and disclaimers.
# Generate ssh host keys if they do not exist.
# Output the public keys to the console. This allows user to get host
# keys securely through console log.
set -eu
prog="$(basename $0)"
logger="logger -t ${prog}"
echo "-----BEGIN SSH HOST KEY FINGERPRINTS-----" | ${logger}
for key in ecdsa ed25519 rsa; do
keyfile="/etc/ssh/ssh_host_${key}_key"
if [ ! -f "${keyfile}" ]; then
/usr/bin/ssh-keygen -f "${keyfile}" -t "${key}" -C 'host' -N ''
fi
/usr/bin/ssh-keygen -l -f "${keyfile}.pub" | ${logger}
done
echo "------END SSH HOST KEY FINGERPRINTS------" | ${logger}