How to Check sha256 Hash of a File on Mac

Dec 17, 2021 - 2 Comments

Mac Terminal icon

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:

23bd4728d59aa19260aaeec757b4f76eca4baebaf33a94f120086c06e7bc80ef ~/Downloads/TopSecret.tgz

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!

.

Related articles:

Posted by: Paul Horowitz in Command Line, Mac OS, Tips & Tricks

2 Comments

» Comments RSS Feed

  1. Bruce says:

    It sure is easy — as long as you know that Apple decided that it would be cleaner to use a non-standard wrapper around the function. “man sha256” does get you a bunch of incomprehensible information about Tcl packages that I don’t want to know about. Things are done in conventional ways for a reason, so “better ideas” aren’t always better, Apple.

  2. Randall says:

    In the following paragraph, did you mean “sha256” instead of “sha236”?

    “Where the string 23bd4728d59aa19260aaeec757b4f76eca4baebaf33a94f120086c06e7bc80ef is the sha236 checksum.”

    If so, the page where this is located is https://osxdaily.com/2021/12/17/check-sha256-hash-mac.

Leave a Reply

 

Shop on Amazon.com and help support OSXDaily!

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates

Tips & Tricks

News

iPhone / iPad

Mac

Troubleshooting

Shop on Amazon to help support this site