david/scripts-archive
david
/
scripts-archive
Archived
1
0
Fork 0
This repository has been archived on 2022-04-16. You can view files and clone it, but cannot push or open issues or pull requests.
scripts-archive/recreate_ssh_host_keys.sh

48 lines
1.2 KiB
Bash
Executable File

#!/bin/bash
#
# recreate ssh host keys
#
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