80 lines
2.0 KiB
Plaintext
80 lines
2.0 KiB
Plaintext
|
#!/bin/sh
|
||
|
|
||
|
# Generate host keys if they are not already present. Taken from sshd
|
||
|
# initscript.
|
||
|
KEYGEN=/usr/bin/ssh-keygen
|
||
|
SSHD=/usr/sbin/sshd
|
||
|
RSA_KEY=/etc/ssh/ssh_host_rsa_key
|
||
|
DSA_KEY=/etc/ssh/ssh_host_dsa_key
|
||
|
ECDSA_KEY=/etc/ssh/ssh_host_ecdsa_key
|
||
|
ED25519_KEY=/etc/ssh/ssh_host_ed25519_key
|
||
|
|
||
|
do_rsa_keygen() {
|
||
|
if [ ! -s $RSA_KEY ]; then
|
||
|
echo -n $"Generating SSH2 RSA host key: "
|
||
|
if $KEYGEN -q -t rsa -b 4096 -f $RSA_KEY -C '' -N '' >&/dev/null; then
|
||
|
chmod 600 $RSA_KEY
|
||
|
chmod 644 $RSA_KEY.pub
|
||
|
echo "Success: RSA key generation"
|
||
|
echo
|
||
|
else
|
||
|
echo "Failure: RSA key generation"
|
||
|
echo
|
||
|
exit 1
|
||
|
fi
|
||
|
fi
|
||
|
}
|
||
|
do_dsa_keygen() {
|
||
|
if [ ! -s $DSA_KEY ]; then
|
||
|
echo -n $"Generating SSH2 DSA host key: "
|
||
|
if $KEYGEN -q -t dsa -f $DSA_KEY -C '' -N '' >&/dev/null; then
|
||
|
chmod 600 $DSA_KEY
|
||
|
chmod 644 $DSA_KEY.pub
|
||
|
echo "Success: DSA key generation"
|
||
|
echo
|
||
|
else
|
||
|
echo "Failure: DSA key generation"
|
||
|
echo
|
||
|
exit 1
|
||
|
fi
|
||
|
fi
|
||
|
}
|
||
|
|
||
|
do_ecdsa_keygen() {
|
||
|
if [ ! -s $ECDSA_KEY ]; then
|
||
|
echo -n $"Generating SSH2 ECDSA host key: "
|
||
|
if $KEYGEN -q -t ecdsa -b 521 -f $ECDSA_KEY -C '' -N '' >&/dev/null; then
|
||
|
chmod 600 $ECDSA_KEY
|
||
|
chmod 644 $ECDSA_KEY.pub
|
||
|
echo "Success: ECDSA key generation"
|
||
|
echo
|
||
|
else
|
||
|
echo "Failure: ECDSA key generation"
|
||
|
echo
|
||
|
exit 1
|
||
|
fi
|
||
|
fi
|
||
|
}
|
||
|
|
||
|
do_ed25519_keygen() {
|
||
|
if [ ! -s $ED25519_KEY ]; then
|
||
|
echo -n $"Generating SSH2 ED25519 host key: "
|
||
|
if $KEYGEN -q -t ed25519 -f $ED25519_KEY -C '' -N '' >&/dev/null; then
|
||
|
chmod 600 $ED25519_KEY
|
||
|
chmod 644 $ED25519_KEY.pub
|
||
|
echo "Success: ED25519 key generation"
|
||
|
echo
|
||
|
else
|
||
|
echo "Failure: ED25519 key generation"
|
||
|
echo
|
||
|
exit 1
|
||
|
fi
|
||
|
fi
|
||
|
}
|
||
|
|
||
|
do_rsa_keygen
|
||
|
do_dsa_keygen
|
||
|
do_ecdsa_keygen
|
||
|
do_ed25519_keygen
|
||
|
exit 0;
|