rcolebaugh / rpms / openssh

Forked from rpms/openssh 2 years ago
Clone
3e8b5b
#!/bin/bash
3e8b5b
3e8b5b
# Create the host keys for the OpenSSH server.
3e8b5b
KEYTYPE=$1
3e8b5b
case $KEYTYPE in
3e8b5b
	"dsa") ;& # disabled in FIPS
3e8b5b
	"ed25519")
3e8b5b
		FIPS=/proc/sys/crypto/fips_enabled
3e8b5b
		if [[ -r "$FIPS" && $(cat $FIPS) == "1" ]]; then
3e8b5b
			exit 0
3e8b5b
		fi ;;
3e8b5b
	"rsa") ;; # always ok
3e8b5b
	"ecdsa") ;;
3e8b5b
	*) # wrong argument
3e8b5b
		exit 12 ;;
3e8b5b
esac
3e8b5b
KEY=/etc/ssh/ssh_host_${KEYTYPE}_key
3e8b5b
3e8b5b
KEYGEN=/usr/bin/ssh-keygen
3e8b5b
if [[ ! -x $KEYGEN ]]; then
3e8b5b
	exit 13
3e8b5b
fi
3e8b5b
3e8b5b
# remove old keys
3e8b5b
rm -f $KEY{,.pub}
3e8b5b
3e8b5b
# create new keys
3e8b5b
if ! $KEYGEN -q -t $KEYTYPE -f $KEY -C '' -N '' >&/dev/null; then
3e8b5b
	exit 1
3e8b5b
fi
3e8b5b
3e8b5b
# sanitize permissions
3e8b5b
/usr/bin/chgrp ssh_keys $KEY
3e8b5b
/usr/bin/chmod 640 $KEY
3e8b5b
/usr/bin/chmod 644 $KEY.pub
3e8b5b
if [[ -x /usr/sbin/restorecon ]]; then
3e8b5b
	/usr/sbin/restorecon $KEY{,.pub}
3e8b5b
fi
3e8b5b
3e8b5b
exit 0