write-ssh-key-fingerprints 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/bin/sh
  2. # This file is part of cloud-init. See LICENSE file for license information.
  3. logger_opts="-p user.info -t ec2"
  4. # rhels' version of logger_opts does not support long
  5. # for of -s (--stderr), so use short form.
  6. logger_opts="$logger_opts -s"
  7. # Redirect stderr to stdout
  8. exec 2>&1
  9. fp_blist=",${1},"
  10. key_blist=",${2},"
  11. {
  12. echo
  13. echo "#############################################################"
  14. echo "-----BEGIN SSH HOST KEY FINGERPRINTS-----"
  15. for f in /etc/ssh/ssh_host_*key.pub; do
  16. [ -f "$f" ] || continue
  17. read ktype line < "$f"
  18. # skip the key if its type is in the blacklist
  19. [ "${fp_blist#*,$ktype,}" = "${fp_blist}" ] || continue
  20. ssh-keygen -l -f "$f"
  21. done
  22. echo "-----END SSH HOST KEY FINGERPRINTS-----"
  23. echo "#############################################################"
  24. } | logger $logger_opts
  25. echo "-----BEGIN SSH HOST KEY KEYS-----"
  26. for f in /etc/ssh/ssh_host_*key.pub; do
  27. [ -f "$f" ] || continue
  28. read ktype line < "$f"
  29. # skip the key if its type is in the blacklist
  30. [ "${key_blist#*,$ktype,}" = "${key_blist}" ] || continue
  31. cat $f
  32. done
  33. echo "-----END SSH HOST KEY KEYS-----"