How To MD5SUM --- 如何检查MD5值?

时间:2022-12-22 12:58:44

windows :

Hash_1.0.4.exe  可以检查md5

https://help.ubuntu.com/community/HowToMD5SUM

Introduction

When one has downloaded an ISO file for installing or trying Ubuntu, it is recommended to test that the file is correct and safe to use. The MD5 calculation gives a checksum (called a hash value), which must equal the MD5 value of a correct ISO.

The program md5sum is designed to verify data integrity using the MD5 (Message-Digest algorithm 5) 128-bit cryptographic hash. MD5 hashes used properly can confirm both file integrity and authenticity.

In terms of integrity, an MD5 hash comparison detects changes in files that would cause errors. The possibility of changes (errors) is proportional to the size of the file; the possibility of errors increase as the file becomes larger. It is a very good idea to run an MD5 hash comparison check when you have a file like an operating system install CD that has to be 100% correct.

In terms of security, cryptographic hashes such as MD5 allow for authentication of data obtained from insecure mirrors. The MD5 hash must be signed or come from a secure source (an HTTPS page) of an organization you trust. See the MD5SUMS file for the release you're using under http://releases.ubuntu.com (and optionally the PGP signatures in the MD5SUMS.gpg file), or refer to the secure UbuntuHashes page for the official list of Ubuntu MD5 hashes.

While security flaws in the MD5 algorithm have been uncovered, MD5 hashes are still useful when you trust the organization that produces them. Moving to more secure hashes like SHA-256 and Whirlpool is under discussion.

md5sum

The official page containing MD5 hashes for Ubuntu, Kubuntu, Edubuntu Xubuntu and Lubuntu is UbuntuHashes. More recent hashes may be available at http://releases.ubuntu.com/ : choose the relevant distribution and click on the MD5SUMS file.

MD5SUM on Linux

Most Linux distributions come with the md5sum utility so installation is usually unnecessary.

Check the iso file

Manual method

First open a terminal and go to the correct directory to check a downloaded iso file:

  • ubuntu@ubuntu-desktop:~$ cd Downloads
  • Linux is case sensitive so "Downloads" is NOT "downloads".

Then run the following command from within the download directory.

  • md5sum ubuntu-11.10-dvd-i386.iso

md5sum should then print out a single line after calculating the hash:

  • 8044d756b7f00b695ab8dce07dce43e5 ubuntu-11.10-dvd-i386.iso

Compare the hash (the alphanumeric string on left) that your machine calculated with the corresponding hash on the UbuntuHashes page.

An easy way to do this is to open the UbuntuHashes page in your browser, then copy the hash your machine calculated from the terminal into the "Find" box in your browser (in Firefox you can open the "Find" box by pressing <Ctrl> <F>).

When both hashes match exactly then the downloaded file is almost certainly intact. If the hashes do not match, then there was a problem with either the download or a problem with the server. You should download the file again from either the same mirror, or from a different mirror if you suspect a server error. If you continuously receive an erroneous file from a server, please be kind and notify the webmaster of that mirror so they can investigate the issue.

Semi-automatic method

Ubuntu distributes the MD5 hashes in a file called MD5SUMS near the bottom of the download page for your release http://releases.ubuntu.com.

First download the MD5SUMS file to the same directory as the iso. Then run the following in a terminal.

  • cd download_directory
    md5sum -c MD5SUMS

md5sum will generate a bunch of warnings. Don't worry: the OK message will be buried somewhere within it!

  • md5sum: ubuntu-8.10-alternate-amd64.iso: No such file or directory
    ubuntu-8.10-alternate-amd64.iso: FAILED open or read
    md5sum: ubuntu-8.10-alternate-i386.iso: No such file or directory
    ubuntu-8.10-alternate-i386.iso: FAILED open or read
    md5sum: ubuntu-8.10-desktop-amd64.iso: No such file or directory
    ubuntu-8.10-desktop-amd64.iso: FAILED open or read
    ubuntu-8.10-desktop-i386.iso: OK
    md5sum: ubuntu-8.10-netbook-remix-i386.img: No such file or directory
    ubuntu-8.10-netbook-remix-i386.img: FAILED open or read
    md5sum: ubuntu-8.10-server-amd64.iso: No such file or directory
    ubuntu-8.10-server-amd64.iso: FAILED open or read
    md5sum: ubuntu-9.04-server-i386.iso: No such file or directory
    ubuntu-8.10-server-i386.iso: FAILED open or read
    md5sum: wubi.exe: No such file or directory
    wubi.exe: FAILED open or read
    md5sum: WARNING: 7 of 8 listed files could not be read

In this case the message we want is on the seventh line.

  • ubuntu-8.10-desktop-i386.iso: OK

Success?

Once you have verified the md5 hash, go ahead and burn the CD. You may want to refer to the BurningIsoHowto page.

Check the CD

So far so good, you have downloaded an iso and verified its integrity. When you boot from the CD you will be given the option to test its integrity. Great, but if the CD is corrupt then you have already wasted time rebooting. You can check the integrity of the CD without rebooting as follows.

Checking the CD directly

You would think you could simply use a command like this to get the MD5 hash of a burned image:

md5sum /dev/cdrom

However this will almost NEVER be the same hash as the iso image that was burned to the disk, because this command includes the empty space at the end of the disk, which changes the hash. So you must check only the part of the disk that was on the iso.

Manual method

First we need to know the size of the iso image. You could open up your favorite graphical file manager such as Nautilus or Dolphin, but since you need to use the command line anyways, you might as well use ls.

ls -l ubuntu-8.10-desktop-i386.iso
-rw-r--r-- 1 jsmith jsmith 732766208 2008-10-28 23:24 ubuntu-8.10-desktop-i386.iso

Now that we know the size of our iso image is 732766208, we can use dd to pipe only 732766208 bytes from our cdrom device into md5sum. Use a block size of 1 and set count to the size of the iso image. Note that this will probably take several minutes, so grab a snack and come back in a while.

dd if=/dev/cdrom bs=1 count=732766208 | md5sum
732766208+0 records in
732766208+0 records out
24ea1163ea6c9f5dae77de8c49ee7c03 -
732766208 bytes (733 MB) copied, 563.666 s, 1.3 MB/s

You could probably speed this up by using a larger block size (bs) and dividing count by the new block size. Since all iso images are multiples of 2048, that is an appropriate block size.

Check the calculated hash (in this case 24ea1163ea6c9f5dae77de8c49ee7c03) against UbuntuHashes as shown for the iso file above. Depending on your system, you may need to change cdrom to cdrom0 (or even cdrom1 if you have two CD drives).

Automated Script

Here is a shell script that will check the md5 hash of a burned disk and compare it to the hash of an iso image. Copy and paste it into your favorite text editor and save it as eg. hashcdrom.sh.

#Compares the checksums of an iso9660 image and a burned disk.
#This script is released into the public domain by it's author.
if [ -n "$BASH" ]; then
shopt -s expand_aliases
fi if [ -n "$FILE" ]; then
FILE="$FILE"
else
FILE=`basename $0`
fi if [ -n "$CHECKSUM" ]; then
alias CHECKSUM="$CHECKSUM"
elif which md5deep &> /dev/null; then
alias CHECKSUM='md5deep -e'
else
alias CHECKSUM='md5sum'
fi if [ -n "$2" ]; then
DISKDEVICE="$2"
else
DISKDEVICE='/dev/cdrom'
fi if [ -n "$1" ]; then
CSUM1=$(CHECKSUM "$1" | grep --only-matching -m 1 '^[0-9a-f]*')
echo 'checksum for input image:' $CSUM1
SIZE=$(stat -c '%s' "$1");
BLOCKS=$(expr $SIZE / 2048);
CSUM2=$(dd if="$DISKDEVICE" bs=2048 count=$BLOCKS 2> /dev/null | CHECKSUM | grep --only-matching -m 1 '^[0-9a-f]*')
echo 'checksum for output disk:' $CSUM2 if [ "$CSUM1" = "$CSUM2" ]; then
echo 'verification successful!'
else
echo 'verification failed!'
fi else
echo ''
echo 'Usage:'
echo ' '$FILE' /path/to/iso [/path/to/cd/drive]'
echo ''
fi

Now open a terminal and type

sh /path/to/hashcdrom.sh /path/to/ubuntu-8.10-desktop-i386.iso /dev/mycdromdevice

Note that if your cdrom device is /dev/cdrom, you can omit that parameter.

It should print out something like

checksum for input image: 24ea1163ea6c9f5dae77de8c49ee7c03
checksum for output disk: 24ea1163ea6c9f5dae77de8c49ee7c03
verification successful!

If you verified that the iso image is okay (above), than you need not check the hash against UbuntuHashes.

This script has some nifty features. For example, if md5deep is installed (sudo aptitude install md5deep), it will use it to print out some progress information, such as how many bytes copied. You can also make it use different hashing algorithms such as sha256 and whirlpool by setting the CHECKSUM environment variable to the command you want to use to create the hash:

export CHECKSUM='whirlpooldeep -e'
sh /path/to/hashcdrom.sh /path/to/ubuntu-8.10-desktop-i386.iso /dev/mycdromdevice

This shell script depends on certain features found only in GNU grep, so it probably will not work on systems that do not ship the GNU utilities.

A method using wodim instead of dd

readom dev=/dev/scd0 sectors=0-352113 f=- |md5sum

where 352113 is result of dividing size of iso file in bytes by 2048.

Check the files on the CD

The MD5 hashes for every file on the CD are listed in a file called md5sum.txt. You can use this file to check the integrity of all the files on the CD.

  • cd /media/cdrom
    md5sum -c md5sum.txt | grep -v "OK$"

This will automatically check every file against the MD5 hashes stored in the file and outputs any failures. (Again, you may need to change cdrom, depending on your system). Beware, it can take a long time so don't worry if your terminal seems to have hung; provided the CD drive is still accessing, it is probably still working. It should not output anything if it there were no errors, and an error message if a file failed the check. Thegrep command option -v "OK$" filters out all of the files that pass the check, because there are usually a lot of them.

Success?

Congratulations, you now have a verified Ubuntu CD. Go ahead and use it (or play frisbee with it if you want).

MD5SUM on Mac OS X

There are three methods of using md5sum on an OS X machine.

Method 1 - The easiest (if MD5 is available) is using the Disk Utility program (Applications > Utilities, or by choosing "Utilities" from the Finder's "Go" menu). Open Disk Utility and wait for it to gather information about your disks. Go to the directory where you downloaded the Ubuntu disk image, and drag it to Disk Utility's dock icon (displays on the left-hand side of Disk Utility, underneath your physical drives). Select the iso file. Go to the "Images" menu and select Checksum > MD5. Be sure to choose "MD5" and NOT "MD5 image checksum" or "CRC-32 image checksum", as they are not the same and will give you different results.

Method 2 - If MD5 is not available in the Images > Checksum menu, open a terminal window (Applications > Utilities > Terminal.app). Type "md5", type a space, drag the iso file into the terminal window (appends command with iso file path), and press Enter. The command line returns the hash number.

Method 3 - You can use the Terminal.app and follow the instructions for MD5SUM on Linux, except use the command "openssl md5" instead of "md5sum".

Each method returns a hash number. Compare the hash number with the corresponding hash on the UbuntuHashes page. When both hashes match exactly, then the downloaded file is almost certainly intact.

If the hashes do not match, then there was a problem with either the download or a problem with the server. You should download the file again from either the same mirror, or from a different mirror if you suspect a server error. If you continuously receive an erroneous file from a server, please notify the webmaster of that mirror so they can investigate the issue.

digest(1) on Solaris

Use the Solaris digest(1) command, specifying the md5 algorithm with the -a flag. For instance:

  • $ digest -a md5 ubuntu-8.10-desktop-i386.iso
    24ea1163ea6c9f5dae77de8c49ee7c03

MD5SUM on Windows

Windows does not come with md5sum. You must download one from another location, preferably one that you trust. There are command line utilities (md5sum.exe) that work similarly to the Unix utility; one public domain version with source is available from Fourmilab, but the version available from Cygwin is probably easier to install and update, and Cygwin is also recommended and trusted as the source for many more Unixy utilities. Once installed, Cygwin's md5sum behaves exactly as described in MD5SUM on Linux above.

There are also graphical tools such as the one used in the walk-through provided below.

  1. Download and install winMD5Sum, a free and open source hash verification program.

  2. Right-click the ISO file.
  3. Click Send To, then winMD5Sum.

  4. Wait for winMD5Sum to load and finish the checksum (this may take a significant amount of time depending on your computer's performance).

  5. Copy the corresponding hash from UbuntuHashes into the bottom text box.

  6. Click "Compare"
    • How To MD5SUM --- 如何检查MD5值?

  7. A message box will say "MD5 Check Sums are the same" if the hashes are equal.

MD5SUM with "Checksums calculator"

"Checksums calculator” is a free file checksum calculation utility, it can support the most commonly used file checksum algorithm, such as md5, crc32, and sha1, can batch process multiple files. This verification software has some useful features, but it is easy to understand and very easy to use. You can download the application here.

  • How To MD5SUM --- 如何检查MD5值?

The program while is running under Windows 7 64bit.

MD5SUM on CD

To see if your Ubuntu CD was corrupted when burned to the disk, see the CDIntegrityCheck page, or follow the instructions below.

First mount the CD, if not already mounted:

  • sudo mount /dev/hda /cdrom

Then use the supplied md5sum file on the CD:

  • cd /cdrom
    md5sum -c md5sum.txt | grep -vi 'OK$'

Be patient, it takes some time. If the command outputs any errors, you'll know that either the burn was bad or the .iso is corrupt. Please note that this method does not verify authenticity unless the hash of the iso file is compared to the hash at the secure UbuntuHashes page.

Finally, you can unmount the CD after leaving the folder:

  • cd /
    sudo umount /dev/hda

External Links

VerifyIsoHowto

在因特网上共享软件包和CD/DVD映像等文件时,通常会一并提供SHA1SUM或MD5SUM文件。这些文件包含校验和,用于确认下载到的文件与仓库发布的完全一致。
下面两个例子分别使用md5sum和sha1sum命令生成文件的校验和:

1
2
3
4
$ md5sum FC-6-i386-rescuecd.iso
54881969da026da24a92db4aab1dcc69  FC-6-i386-rescuecd.iso
$ sha1sum FC-6-i386-rescuecd.iso
834fd761b9c0a5dc550d10d97307dac998103a68  FC-6-i386-rescuecd.iso

具体选用哪个命令视(待核对的)文件提供者发布的是md5sum还是sha1sum信息而定。例如,下面是Fedora 6发行版的SHA1SUM文件内容:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
 
834fd761b9c0a5dc550d10d97307dac998103a68  FC-6-i386-rescuecd.iso
cc503d99c9d736af9052904a6ab14931b0850078  FC-6-i386-disc1.iso
3051710e6b2f1d17a14ede0ebb74761c29cda954  FC-6-i386-disc2.iso
5357ce21f8766db385b25923216a430b694bca5d  FC-6-i386-disc3.iso
d6133ab5ccf19431c14fd2ad85bce03c9834ef87  FC-6-i386-disc4.iso
6722f95b97e5118fa26bafa5b9f622cc7d49530c  FC-6-i386-DVD.iso
22327af62d6376916e209b0c4934540e14d5664a  FC-6-i386-disc5.iso
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)
 
iD8DBQFFNo/utEJp0E8qb9IRAsf7AJ9ZqiDlKqJfAh8g5QHyDMmPOzNbTACfbyGw
hB8bkLBT+6ANW6y8iBmlxz8=
=O/Le
-----END PGP SIGNATURE-----

上面的SHA1SUM文件及其列出的ISO文件都位于当前目录时,使用sha1sum加-c选项可以一次检验所有ISO文件。示例如下:

1
2
3
4
5
6
7
8
$ sha1sum -c SHA1SUM
FC-6-i386-rescuecd.iso: OK
FC-6-i386-disc1.iso: OK
FC-6-i386-disc2.iso: OK
FC-6-i386-disc3.iso: OK
FC-6-i386-disc4.iso: OK
FC-6-i386-DVD.iso: OK
FC-6-i386-disc5.iso: OK

运行下面的命令可以检验其中一个文件(SHA1SUM文件所列):

1
2
$ cat SHA1SUM | grep rescuecd |sha1sum -c
FC-6-i386-rescuecd.iso: OK

使用md5sum命令可以比照MD5SUM文件(而不是SHA1SUM文件)检验文件,用法同上。结合本章之前介绍的find命令和md5sum命令,可以检验文件系统的任意部分。例如,下面的命令行会对/etc目录下的每个文件创建MD5校验和,之后可以核对这些文件,确认有无改动:

# find /etc -type f -exec md5sum {} \; 2>/dev/null > /tmp/md5.list

上述命令行的运行结果是/tmp/md5.list文件,包含/etc目录下每个文件的128位校验和。之后键入下面的命令即可查看文件有无改动:

1
2
3
4
# cd /etc
# md5sum -c /tmp/md5.list | grep -v 'OK'
./hosts.allow: FAILED
md5sum: WARNING: 1 of 1668 computed checksums did NOT match

从上面的输出可以看出,只有一个文件有改动(hosts.allow)。下一步就是检查那个改动过的文件,确认对文件的改动是否有意为之。

How To MD5SUM --- 如何检查MD5值?的更多相关文章

  1. md5sum检验MD5值

    md5sum命令检验MD5值 md5sum命令用于生成和校验文件的md5值.它会逐位对文件的内容进行校验.是文件的内容,与文件名无关,也就是文件内容相同,其md5值相同.md5值是一个128位的二进制 ...

  2. linux下md5sum用法 &lpar;查看文件或字符串的md5值&rpar;

    MD5算法常常被用来验证网络文件传输的完整性,防止文件被人篡改.MD5 全称是报文摘要算法(Message-Digest Algorithm 5),此算法对任意长度的信息逐位进行计算,产生一个二进制长 ...

  3. md5sum 计算和校验文件的md5值

    1. 命令功能 md5算法一般用于检查文件完整性, 2. 语法格式 md5sum  [option]  [file] 参数 参数说明 -b 以二进制模式读入文件 -t 以文本模式读入文件 -c 用来从 ...

  4. 【Linux】md5sum 生产所有文件的md5值,并对照目标文件是否相同

    现在加入有很多很多文件需要测试md5,想看下是否都传输成功了,如何批量生成文件的md5并且逐条对照呢? 下面来简单介绍下 md5sum这个命令有一个选项"-c" 这个选项的意思是c ...

  5. Linux MD5值递归比对目录中的文件是否有修改

    项目上今天遇到检查两个版本的发布包rc1.tar.gz和rc2.tar.gz的一致性,解决方法做个总结,步骤如下 1. 建立文件夹 mkdir test_rc1 test_rc2 2. 文件解压缩 t ...

  6. md5值计算

    1.md5(Message Digest 5th/消息概要加密算法 第5版) REFER: MD5 On wikipedia 2.应用范围 ① 验证下载文件的完整性 ② 3.关于MD5的几个问题 ①只 ...

  7. linux shell 命令获取字符串&sol;文件的MD5值

    获取字符串的MD5值: 字符串“hello”的MD5: $ echo -n 'hello'|md5sum|cut -d ' ' -f1 得到的MD5值: 5d41402abc4b2a76b9719d9 ...

  8. md5值校验

    使用哈希的md5给文件加指纹,如果文件被更改,指纹信息就会不匹配,从而确定文件的原值是否被改动. [root@b test]# md5sum a.txt > zhiwen.txt[root@b ...

  9. 查看文件MD5值

    Windows 打开命令窗口(Win+R),然后输入cmd ·输入命令certutil -hashfile 文件绝对路径 MD5 Linux MD5算法常常被用来验证网络文件传输的完整性,防止文件被人 ...

随机推荐

  1. 使用ASP&period;NET Web Api构建基于REST风格的服务实战系列教程【三】——Web Api入门

    系列导航地址http://www.cnblogs.com/fzrain/p/3490137.html 前言 经过前2节的介绍,我们已经把数据访问层搭建好了,从本章开始就是Web Api部分了.在正式开 ...

  2. pod 安装 Masonry 遇到问题

    pod 导入第三方库 Masonry: 在工程masonryTest的文件下新建一个Podfile文件 编辑如下内容: platform :ios, '8.0'xcodeproj 'mansoryTe ...

  3. 在项目中 background transiton 带来的&quot&semi;便利&quot&semi;与&OpenCurlyDoubleQuote;坑”

    本文就两个例子跟大家分享一下background-image与background-size的渐变(transition)所带来的方便与“深坑” 首选,说说这东西好的地方,有时候在做PC项目的时候,可 ...

  4. Codeforces Round &num;303 &lpar;Div&period; 2&rpar; E&period; Paths and Trees 最短路&plus;贪心

    题目链接: 题目 E. Paths and Trees time limit per test 3 seconds memory limit per test 256 megabytes inputs ...

  5. Raspberry Pi(树莓派)上从零开始构建Linux系统(简称PiLFS)(一)

    一. 准备工作 1. 装有Linux宿主系统的树莓派主板,可参考 Raspberry Pi(树莓派)上安装Raspbian(无路由器,无显示器) 2. 参考网址:Linux From Scratch ...

  6. spark使用总结

    背景 使用spark开发已有几个月.相比于python/hive,scala/spark学习门槛较高.尤其记得刚开时,举步维艰,进展十分缓慢.不过谢天谢地,这段苦涩(bi)的日子过去了.忆苦思甜,为了 ...

  7. pip 使用豆瓣源

    pip 使用豆瓣源 由于pip 默认使用Python的官方源pypi.python.org/pypi,导致我们经常使用pip装包时速度过慢或者无法安装(请求超时)等问题, 所以国内用户建议使用pip ...

  8. SNF快速开发平台MVC-富文本控件集成了百度开源项目editor

    一.效果如下: 二.在框架当中调用代码如下: 1.在js里配置如下: <script type="text/javascript"> var viewModel =fu ...

  9. php有效防止同一用户多次登录

    PHP实现同一个帐号不允许多人同时重复登陆 数据库表 user_login_info字段:id,user_ip,user_id,last_access_timeuser_id 做唯一性索引1. 用户登 ...

  10. Jacobi并行拆解【补充】

    作者:桂. 时间:2018-04-24  22:04:52 链接:http://www.cnblogs.com/xingshansi/p/8934373.html 前言 本文为Jacobi并行拆解一文 ...