Need to check the sha256 hash of a file? You can easily check the SHA 256 checksum of any file in macOS from the command line.
We’ll cover two different command line tools to verify a sha256 checksum on the Mac, and both come preinstalled with all modern versions of MacOS.
For those who are not familiar, a checksum is basically a string of letters and numbers that can be used to determine file integrity, like whether an error occurred during transmission, or whether a file was tampered with. For example, if the file checksum matches on your end with the checksum posted by where you received the file, you can be sure the file is identical. There are a variety of types of hashes and checksums, but what we’ll cover here is sha256.
Verifying SHA256 checksum with shasum
The shasum command is available on all modern Macs and can be used to check sha256 hash.
Launch Terminal and then use the following command, replacing /path/to/file with the file path as appropriate:
shasum -a 256 /path/to/file
For example, to check the sha256 hash of a file called “TopSecret.tgz” in the user Downloads folder, you could use the following:
shasum -a 256 ~/Downloads/TopSecret.tgz
You’ll see something like:
Where the string 23bd4728d59aa19260aaeec757b4f76eca4baebaf33a94f120086c06e7bc80ef is the sha236 checksum.
Checking sha256 hash with openssl
You can also check and verify sha256 hash by using the openssl command.
From Terminal.app, use the following command:
openssl sha256 filename
For example, to verify the sha256 hash of a file named “Data Integrity Matters.pdf” located in the user Documents folder:
openssl sha256 ~/Documents/"Data Integrity Matters.pdf"
This will return something like the following:
SHA256(/Users/User/Documents/Data Integrity Matters.pdf)= b85775615fa5501afeb9b9ff1303a4c74e14367104oo824e667daebebe681129c
With the large string of numbers nd characters being the sha256 hash.
If you’re already familiar with the general process of checking hashes, whether it be checking sha1 checksums or MD5 hash, then this process and the commands may not come as much of a surprise to you, though the latter uses a different command specific to md5.
Whether you want to verify a SHA-512 checksum, SHA-256 hash, SHA-1 hash, or MD5 checksum, you can do any through the command line on the Mac. Have at it!