How to Use: sha256sum

Prerequisites Link to heading

Create a basic file:

echo "abc123" > test123.txt

Digest Link to heading

Find the sha256sum of a file with:

sha256sum test123.txt

You will get the following result:

5ecf8d2cc410094e8b82dd0bc178a57f3aa1e80916689beb00fe56148b1b1256  test123.txt

NOTE: there are 2 spaces between the digest and file name. TWO  SPACES!!!

Save that result into a file for easy checking:

sha256sum test123.txt > test123.txt.sha256

Check Link to heading

If there’s a sha256 file available, you can do:

sha256sum --check test123.txt.sha256

Success Link to heading

test123.txt: OK

Failure Link to heading

Change the file contents:

echo "zzz987" > test123.txt

Now you get a different message and exit code 1:

test123.txt: FAILED
sha256sum: WARNING: 1 computed checksum did NOT match

Scripting Link to heading

In scripts, like Dockerfile RUN instructions you might wan to check the sha256sum inline:

SHA=61bfc547a623d7305256611a81ecd24e6bf9dac555529ed6baeafcf8160900da
PACKAGE=your-file.tar.gz
echo "$SHA  $PACKAGE" | sha256sum -c -

NOTE: there are 2 spaces between the digest and file name. TWO  SPACES!!!