This Bash script allows you to verify the integrity of a file by calculating its SHA256 hash and comparing it with a user-provided reference hash.
- Accepts a file path from the user
- Calculates the file's SHA256 hash
- Asks for a custom SHA256 hash to compare against
- Outputs PASS in green if the hashes match
- Outputs FAIL in red if the hashes do not match
- A Linux terminal with Bash
sha256suminstalled (available by default on most distributions)
chmod +x shaSignatureCheck.sh./shaSignatureCheck.sh-
Full file path, for example:
/home/youruser/Downloads/example.pdf -
SHA256 hash to verify, for example:
d2d2d0efbdccd03a693a80101c3fd50bbca541b7fae0e70...
File path: /home/user/Downloads/Document.pdf
Enter your reference SHA256 hash: e3b0c44298fc1c149afbf4c8996fb924...
PASS - Hashes match.or
FAIL - Hashes do NOT match.#!/bin/bash
GRUEN='\033[0;32m'
ROT='\033[0;31m'
NC='\033[0m'
read -p "Path to the file: " dateipfad
if [[ ! -f "$dateipfad" ]]; then
echo -e "${ROT}Error: File not found.${NC}"
exit 1
fi
datei_sha=$(sha256sum "$dateipfad" | awk '{ print $1 }')
read -p "Own SHA256-Signature to check: " benutzer_sha
if [[ "$datei_sha" == "$benutzer_sha" ]]; then
echo -e "${GRUEN}PASS - Singature are the same.${NC}"
else
echo -e "${ROT}FAIL - Signaturen are'nt the same.${NC}"
fiTo make the script globally accessible from anywhere:
mkdir -p ~/bin
cp shaSignatureCheck.sh ~/bin/checksha
chmod +x ~/bin/checkshaThen simply run:
checkshaThis script is licensed under the MIT License. Use it freely at your own risk.