File integrity
If providing downloadable files, it is important to ensure that the downloaded file is the same as that provided on the host server, this ensures the file has not been tampered with in some way. The end user needs a way to check what they have downloaded is safe.
One way to do this is to create a file checksum with md5sum
let's say we have two files
-rw-rw-r-- 1 psutton psutton 67200 May 3 19:42 jcr.pdf
-rw-rw-r-- 1 psutton psutton 433231 Apr 28 17:50 southwest1.png
We want to create a checksum for both files. To do this we can run
md5sum southwest1.png
502d4f9dacab9240f2622c032e6ea11f southwest1.png
md5sum jcr.pdf
b98edf4dd0afd0ede8ac6dabce66f522 jcr.pdf
This sends the checksum to stdout
So need a file to store this
md5sum jcr.pdf southwest1.png > md5sum2
We can then view the contents if this with
as previously discussed the > directs output to a specified file
cat md5sums
502d4f9dacab9240f2622c032e6ea11f southwest1.png
b98edf4dd0afd0ede8ac6dabce66f522 jcr.pdf
In this example, we listed the files we want to create a checksum for.
If we were to add a 3rd file say tux.png then we can do this and append the new checksum with
md5sum tux.png >> md5sums
Then example our new md5sums file
cat md5sums
502d4f9dacab9240f2622c032e6ea11f southwest1.png
b98edf4dd0afd0ede8ac6dabce66f522 jcr.pdf
d52cd5e7164eccd6da50e10d5a9c3dbf tux.png
So now that we have 3 files and a md5sums file, we can check all the files listed
md5sum -c md5sums
southwest1.png: OK
jcr.pdf: OK
tux.png: OK
Chat
I am on the Devon and Cornwall Linux user group mailing list and also their matrix channel as zleap, it is better to ask there, that way others can answer too.
Tags
#Bash,#BashScripting,#Bashscripting,#md5sums,#md5sum,#file, #integrity,#check
Mastodon | ShellLabs | Join Mastodon |