01-renew-ssh-keys 596 B

123456789101112131415161718192021222324252627282930
  1. #!/bin/bash
  2. # Licence : GPL v3
  3. # Author: Laurent HUBERT
  4. #
  5. # Renews the ssh server keys if they exist
  6. #
  7. cat <<EOF
  8. ##################################
  9. # Renewing SSH server keys #
  10. ##################################
  11. EOF
  12. status=0
  13. renew_ssh_keys(){
  14. rm /etc/ssh/ssh_host_*key*
  15. dpkg-reconfigure openssh-server
  16. status=$?
  17. }
  18. ls /etc/ssh/ssh_host_*key* > /dev/null 2>&1 && renew_ssh_keys || status=1
  19. if [ 0 -ne "$status" ]
  20. then
  21. # Exit with non zero status
  22. echo "Error renewing SSH keys"
  23. exit 1
  24. else
  25. cat <<-EOF
  26. # Renewing SSH server keys: OK #
  27. ##################################
  28. EOF
  29. fi