Created
May 22, 2024 16:09
-
-
Save iangmaia/2e1eac303216bc7d815d7645acbae9f8 to your computer and use it in GitHub Desktop.
Search for a SHA256 fingerprint in key files within a directory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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