2013-06-23 12:52:36 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#
|
|
|
|
# recreate ssh host keys
|
|
|
|
#
|
|
|
|
|
2013-06-23 13:41:55 +02:00
|
|
|
sshdconfig="/etc/ssh/sshd_config"
|
|
|
|
|
|
|
|
if [ $(whoami) != "root" ]; then
|
|
|
|
echo "you need to be root"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -r $sshdconfig ]; then
|
|
|
|
while read line; do
|
|
|
|
fletter=${line:0:1}
|
|
|
|
if [ -z $fletter ]; then
|
|
|
|
#empty line. skipping.
|
|
|
|
:
|
|
|
|
elif [ $fletter == "#" ]; then
|
|
|
|
#comment. skipping.
|
|
|
|
:
|
|
|
|
else
|
|
|
|
echo $line | grep "HostKey" >> /dev/null
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
file=$(echo $line | awk '{print $2}')
|
|
|
|
if [ $file != "${file/_dsa_/}" ]; then
|
|
|
|
mv $file $file.old
|
|
|
|
mv $file.pub $file.pub.old
|
|
|
|
ssh-keygen -t dsa -f $file
|
|
|
|
elif [ $file != "${file/_ecdsa_/}" ]; then
|
|
|
|
mv $file $file.old
|
|
|
|
mv $file.pub $file.pub.old
|
|
|
|
ssh-keygen -t ecdsa -f $file
|
|
|
|
elif [ $file != "${file/_rsa_/}" ]; then
|
|
|
|
mv $file $file.old
|
|
|
|
mv $file.pub $file.pub.old
|
|
|
|
ssh-keygen -t rsa -f $file
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done < $sshdconfig
|
|
|
|
exit 0
|
|
|
|
else
|
|
|
|
echo "$sshdconfig - file not found"
|
|
|
|
exit 1
|
|
|
|
fi
|