ssh_host_key_gen/ssh_host_key_gen.sh
2018-06-07 05:48:01 -07:00

37 lines
525 B
Bash

#!/bin/bash
#
# This script regenerates the SSH host keys on a newly,
# template created, VM
#
# Add the full path of the script in /etc/rc.local, just
# above 'exit 0'
if which systemctl
then
systemctl stop ssh
else
service ssh stop
fi
if ls /etc/ssh/ssh_host_* &> /dev/null
then
rm -f /etc/ssh/ssh_host_*
fi
ls /etc/ssh/ssh_host_* &> /dev/null
if [ "$?" -ne 0 ]
then
ssh-keygen -A
fi
if which systemctl
then
systemctl start ssh
else
service ssh start
fi
sed -i "/$0/d" /etc/rc.local
rm -f $0