vishalmishra434 / rpms / openssh

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