Skip to content

Instantly share code, notes, and snippets.

@iangmaia
Created May 22, 2024 16:09
Show Gist options
  • Save iangmaia/2e1eac303216bc7d815d7645acbae9f8 to your computer and use it in GitHub Desktop.
Save iangmaia/2e1eac303216bc7d815d7645acbae9f8 to your computer and use it in GitHub Desktop.
Search for a SHA256 fingerprint in key files within a directory
#!/bin/bash
extract_fingerprint() {
ssh-keygen -lf "$1" -E sha256 2>/dev/null | awk '{print $2}'
}
if [ "$#" -ne 2 ]; then
echo "Usage: $0 <DIRECTORY> <SHA256_FINGERPRINT>"
exit 1
fi
DIRECTORY=$1
SHA256_FINGERPRINT=$2
find "$DIRECTORY" -type f | while read -r file; do
FILE_FINGERPRINT=$(extract_fingerprint "$file")
if [ "$FILE_FINGERPRINT" == "$SHA256_FINGERPRINT" ]; then
echo "Match found: $file"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment