openssh/openssh-sshd-makecerts

88 lines
1.9 KiB
Bash

#!/bin/sh
RSA1_KEY=/etc/ssh/ssh_host_key
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
KEYGEN=/usr/bin/ssh-keygen
function do_rsa1_keygen
{
if [ ! -s $RSA1_KEY ]; then
echo -n $"Generating SSH1 RSA host key: "
if $KEYGEN -q -t rsa1 -f $RSA1_KEY -C '' -N '' >&/dev/null; then
chmod 600 $RSA1_KEY
chmod 644 $RSA1_KEY.pub
else
echo $"RSA1 key generation failed!"
exit 1
fi
fi
}
function do_rsa_keygen
{
if [ ! -s $RSA_KEY ]; then
echo -n $"Generating SSH2 RSA host key: "
if $KEYGEN -q -t rsa -f $RSA_KEY -C '' -N '' >&/dev/null; then
chmod 600 $RSA_KEY
chmod 644 $RSA_KEY.pub
else
echo $"RSA key generation failed!"
exit 1
fi
fi
}
function 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
else
echo $"DSA key generation failed!"
exit 1
fi
fi
}
function do_ecdsa_keygen
{
if [ ! -s $ECDSA_KEY ]; then
echo -n $"Generating SSH2 ECDSA host key: "
if $KEYGEN -q -t ecdsa -f $ECDSA_KEY -C '' -N '' >&/dev/null; then
chmod 600 $ECDSA_KEY
chmod 644 $ECDSA_KEY.pub
else
failure $"ECDSA key generation failed!"
exit 1
fi
fi
}
function 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
else
failure $"ED25519 key generation failed!"
exit 1
fi
fi
}
# Create keys if necessary
do_rsa_keygen
do_rsa1_keygen
do_dsa_keygen
do_ecdsa_keygen
do_ed25519_keygen
exit 0