| 123456789101112131415161718192021222324252627282930313233343536 |
- #!/bin/bash
- # Licence : GPL v3
- # Author: Laurent HUBERT
- #
- # Renews the ssh server keys if they exist
- #
- cat <<EOF
- +---------------------------------------------+
- | Renewing SSH server keys |
- +---------------------------------------------+
- EOF
- status=0
- renew_ssh_keys(){
- rm /etc/ssh/ssh_host_*key*
- dpkg-reconfigure openssh-server
- status=$?
- }
- # Disables to avoid error messages
- systemctl disable ssh
- systemctl stop ssh
- ls /etc/ssh/ssh_host_*key* > /dev/null 2>&1 && renew_ssh_keys || status=1
- systemctl enable ssh
- systemctl start ssh
- if [ 0 -ne "$status" ]
- then
- # Exit with non zero status
- echo "### Error renewing SSH keys ###"
- exit 1
- else
- echo "> Renewing SSH server keys : OK <"
- systemctl start ssh
- exit 0
- fi
|