2011-06-28 10:01:11 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# Create the host keys for the OpenSSH server.
|
2016-03-16 08:57:22 +00:00
|
|
|
KEYTYPE=$1
|
|
|
|
case $KEYTYPE in
|
|
|
|
"dsa") ;& # disabled in FIPS
|
|
|
|
"ed25519")
|
|
|
|
FIPS=/proc/sys/crypto/fips_enabled
|
|
|
|
if [[ -r "$FIPS" && $(cat $FIPS) == "1" ]]; then
|
|
|
|
exit 0
|
|
|
|
fi ;;
|
|
|
|
"rsa") ;; # always ok
|
|
|
|
"ecdsa") ;;
|
|
|
|
*) # wrong argument
|
|
|
|
exit 12 ;;
|
|
|
|
esac
|
|
|
|
KEY=/etc/ssh/ssh_host_${KEYTYPE}_key
|
2011-06-28 10:01:11 +00:00
|
|
|
|
|
|
|
KEYGEN=/usr/bin/ssh-keygen
|
2016-03-16 08:57:22 +00:00
|
|
|
if [[ ! -x $KEYGEN ]]; then
|
|
|
|
exit 13
|
|
|
|
fi
|
2013-10-23 20:51:32 +00:00
|
|
|
|
2016-03-16 08:57:22 +00:00
|
|
|
# remove old keys
|
|
|
|
rm -f $KEY{,.pub}
|
2014-04-09 11:37:47 +00:00
|
|
|
|
2016-03-16 08:57:22 +00:00
|
|
|
# create new keys
|
|
|
|
if ! $KEYGEN -q -t $KEYTYPE -f $KEY -C '' -N '' >&/dev/null; then
|
|
|
|
exit 1
|
2011-06-28 10:01:11 +00:00
|
|
|
fi
|
2014-04-09 11:37:47 +00:00
|
|
|
|
2016-03-16 08:57:22 +00:00
|
|
|
# sanitize permissions
|
|
|
|
/usr/bin/chgrp ssh_keys $KEY
|
|
|
|
/usr/bin/chmod 640 $KEY
|
|
|
|
/usr/bin/chmod 644 $KEY.pub
|
|
|
|
if [[ -x /usr/sbin/restorecon ]]; then
|
|
|
|
/usr/sbin/restorecon $KEY{,.pub}
|
|
|
|
fi
|
2014-04-09 11:37:47 +00:00
|
|
|
|
2016-03-16 08:57:22 +00:00
|
|
|
exit 0
|