BASH   28

compare sh

Guest on 17th June 2022 01:14:33 AM

  1. #!/bin/sh
  2. #
  3. # Script compiled by Edmund Laugasson
  4. #
  5. # The following script will compare hashes to ensure
  6. # we are logging into appropriate SSH server
  7. #
  8. # Run the current script by command
  9. # source script.sh (replace "script" with real file name)
  10. #
  11. # Usually querying from Linux will give the fingerprint using ECDSA algorithm
  12. # and from MS Windows MD5 fingerprint.
  13. # Compare fingerprints in same format and by same algorithm.
  14. # Same applies to key hashes or whatever else there will be compared.
  15. #
  16. # Querying the appropriate key fingerprint from server can be done e.g.:
  17. # ssh-keyscan -t <algorithm> <IP> | ssh-keygen -lf -
  18. # replace <algorithm> with ecdsa, rsa, ed25519 and <IP> with real server IP-address
  19. #
  20. # To query all available fingerprints:
  21. # ssh-keyscan <IP> | ssh-keygen -lf -
  22. #
  23. # Certainly you can compare whatever else, e.g. public key hashes
  24. # You can query all available public keys hash e.g.
  25. # ssh-keyscan <IP>
  26. #
  27. # or by specifying type:
  28. # ssh-keyscan -t <algorithm> <IP>
  29. # replace <algorithm> with ecdsa, rsa, ed25519 and <IP> with real server IP-address
  30. #
  31. # So, below the "hash" means either fingerprint or hash of SSH key.
  32. # Certainly there can be compared almost any strings.
  33. #
  34. #
  35. hash1="" #put the hash between quotation marks you got from server administrator
  36. hash2="" #put the hash between quotation marks you queried directly from server
  37. if [ "$hash1" == "$hash2" ]
  38. then
  39.   echo "Compared values are the same. If these were either fingerprints or hashes of remote computer then it is safe to log in!"
  40.   else
  41.   echo "Compared values are NOT the same, it must be investigated further!"
  42. fi

Raw Paste


Login or Register to edit or fork this paste. It's free.