如何在Linux中检查文件的完整性?

In today IT world everything connected and a lot of data is being downloaded from the internet or over networks. This may create some minor problems. The data downloaded may be corrupted or there may be some intruders in network and with the man of the middle attack may change our files. There are different solutions for this but the simplest and fastest solution is using hash algorithms to verify file integrity. There are the different hash function to use but MD5 and SHA1 are popular ones.

在当今的IT世界中,万物互联,并且可以从Internet或网络上下载大量数据。 这可能会产生一些小问题。 下载的数据可能已损坏,或网络中可能有一些入侵者,并且受到中间攻击的人可能会更改我们的文件。 对此有不同的解决方案,但是最简单,最快的解决方案是使用哈希算法来验证文件完整性。 可以使用不同的哈希函数,但是MD5和SHA1是流行的。

nmap
nmap
纳帕

下载Nmap(Download Nmap)

We will download nmap package named nmap-7.31.tgz from nmap.org . We will use this file as an example where this file hash is already provided by Nmap web site.

我们将下载nmap姓包nmap-7.31.tgznmap.org 。 我们将以该文件为例,其中Nmap网站已经提供了该文件哈希。

$ wget https://nmap.org/dist/nmap-7.21.tgz
Download Nmap
Download Nmap
下载Nmap

从网站获取哈希值 (Get Hash Values From Site)

We will calculate hash of downloaded file nmap-7.31.tgz 

我们将计算下载文件nmap-7.31.tgz的哈希值

Get Hash Values From Site
Get Hash Values From Site
从网站获取哈希值

Here are the contents of the hash file about the downloaded Nmap source file with the name of nmap-7.31.tgz.digest.txt.

以下是有关名为nmap-7.31.tgz.digest.txt的已下载Nmap源文件的哈希文件的内容。

Get Hash Values From Site
Get Hash Values From Site
从网站获取哈希值

计算哈希(Calculate Hash)

We will use sha1sum to calculate SHA1 , md5sum to calculate MD5 sha24sum to calculate SHA256 and sha512sum to calculate SHA512 of the given file.

我们将使用sha1sum计算SHA1md5sum计算MD5 sha24sum计算SHA256sha512sum计算给定文件的SHA512

$ sha1sum nmap-7.31.tgz
$ md5sum nmap-7.31.tgz
$ sha224sum nmap-7.31.tgz 
$ sha512sum nmap-7.31.tgz
Calculate Hash
Calculate Hash
计算哈希

As we see newer SHA version creates longer hash because they are more secure and complex. If we check the calculated hash and web site provided hash we can see that everything is OK.

如我们所见,较新的SHA版本会创建更长的哈希,因为它们更安全,更复杂。 如果检查计算出的哈希值和网站提供的哈希值,我们可以看到一切正常。

LEARN MORE  How To Verify Files and Signatures with PGP In Linux?
了解更多如何在Linux中使用PGP验证文件和签名?

翻译自: https://www.poftut.com/how-to-check-integrity-of-files-in-linux/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值