Linux sha256 from file

Linux sha256sum command

On Unix-like operating systems, the sha256sum command computes and checks a SHA256 encrypted message digest.

This page describes the GNU/Linux version of sha256sum.

Description

The sha256sum command displays or checks SHA256 (256-bit) checksums. With no FILE, or when FILE is — (a dash), it reads the digest from standard input.

Syntax

Options

-b, —binary Read in binary mode.
-c, —check Read SHA256 sums from the FILEs and check them.
—tag Create a BSD-style checksum.
-t, —text Read in text mode (default).

There is no difference between binary and text mode option on GNU system.

The following four options are useful only when verifying checksums:

—quiet Don’t print OK for each successfully verified file.
—status Don’t output anything, status code shows success.
—strict Exit non-zero for improperly formatted checksum lines.
-w, —warn Warn about improperly formatted checksum lines.
—help Display this help and exit.
—version Output version information and exit.

The sums are computed as described in FIPS-180-2. When checking, the input should be a former output of this program. The default mode is to print a line with checksum, a character indicating input mode (‘*’ for binary, space for text), and name for each FILE.

Examples

Running the above command would give the SHA256 checksum of the example.iso file in the current directory. Below is an example of how the output may appear with the full SHA256 checksum followed by the file name.

md5sum — Checks the MD5 message digest.
sha224sum — Checks the SHA224 message digest.
sha384sum — Checks the SHA384 message digest.
sha512sum — Checks the SHA512 message digest.

Источник

How to Verify Checksum on Linux [Beginner Guide]

Last updated April 10, 2020 By Munif Tanjim 35 Comments

Brief: This beginner’s guide tells you what a checksum checks, what MD5, SHA-256 and SHA-1 checksums are, why checksums are used and how to verify checksums on Linux.

You’ll learn the following in this tutorial:

What is a Checksum?

A checksum is like the digital fingerprint of a file. In technical terms,

A checksum is a small-sized datum from a block of digital data for the purpose of detecting errors which may have been introduced during its transmission or storage.

So a checksum is a long string of data containing various letters and numbers. You’ll generally find them when downloading files from the web, e.g. Linux distribution images, software packages, etc.

The most common use of checksums is for checking if a downloaded file is corrupted.

For instance, the Ubuntu MATE download page includes an SHA-256 checksum for every image it makes available. So after you’ve downloaded an image, you can generate an SHA-256 checksum for it and verify that the checksum value matches the one listed on the site.

Читайте также:  Как выбрать время обновления windows 10

If it doesn’t, that means your downloaded image’s integrity is compromised (maybe it was corrupted during the download process). We will use an Ubuntu MATE “ubuntu-mate-16.10-desktop-amd64.iso” image file for this guide.

How is a Checksum generated?

Each checksum is generated by a checksum algorithm. Without going into the technical details let’s just say it takes a file as input and outputs the checksum value of that file. There are various algorithms for generating checksums. The most popular checksum algorithms are:

  • Secure Hash Algorithms and variants (SHA-1, SHA-2 etc.)
  • MD5 algorithm

Let’s see how to verify a checksum on Linux.

How to use checksum to verify file integrity [GUI way]

If you’re looking for a graphical solution, you can use GtkHash.

GtkHash is a nifty tool for generating and verifying various checksums. It supports a wide range of checksum algorithms, including SHA, MD5 and others. Here’s a list of supported algorithms:

GtkHash supported Checksum Algorithms

Installing GtkHash on Ubuntu

To install GtkHash on your Ubuntu system, simply run the following command:

That’s it. Then select the checksum algorithms to use:

  • Go to Edit >Preferences in the menu.
  • Select the ones you’d like to use.
  • Hit the Close button.

By default, MD5, SHA-1 and SHA256 are selected.

Using GtkHash

Using it is quite straight-forward.

  • Select the file you want to check.
  • Get the Checksum value from the website and put it in the Check box.
  • Click the Hash button.
  • This will generate the checksum values with the algorithms you selected.
  • If any one of them matches with the Check box, it will show a small tick sign beside it.

Here’s an example showing GtkHash generating a checksum for the Ubuntu MATE iso image (ubuntu-mate-16.10-desktop-amd64.iso):

GtkHash with UbuntuMATE iso

Verify checksums via Linux command line

Every Linux distribution comes with tools for various checksum algorithms. You can generate and verify checksums with them. The command-line checksum tools are the following:

  • MD5 checksum tool is called md5sum
  • SHA-1 checksum tool is called sha1sum
  • SHA-256 checksum tool is called sha256sum

There are some more available, e.g. sha224sum, sha384sum, etc. All of them use similar command formats. Let’s see an example using sha256sum. We’ll use the same “ubuntu-mate-16.10-desktop-amd64.iso” image file that we used before.

Generating and Verifying SHA256 Checksum with sha256sum

First go to the directory where the .iso image is stored:

Now, to generate the SHA-256 checksum, enter the following command:

You’ll see the SHA-256 checksum in your terminal window! Easy, isn’t it?

Generating SHA256 Checksum for UbuntuMATE iso

If the generated checksum matches the one provided on the Ubuntu MATE download page, that will mean no data was changed while you downloaded the file – in other words, your downloaded file is not corrupted.

The other tools mentioned work similarly.

How accurately does this work?

If you’re wondering how accurately these checksums detect corrupted files – if you delete or change even one character from any one of the text files inside the iso image, the checksum algorithm will generate a totally different value for that changed image. And that will definitely not match the checksum provided on the download page.

Читайте также:  Модификации для mac os

Do you checksum?

One of the suggested steps while installing Linux is to verify the checksum of your Linux ISO. Do you always follow this step or do you do it only when something goes wrong with the installation?

Was this guide helpful? If you have any questions, let us know! And if you need a similar guide for something else, reach out to us, we’re here to help.

Like what you read? Please share it with others.

Источник

How to Verify SHA256 Checksum of File in Linux

Internet security is one of the most important aspects when it comes to the world wide web. There has been constant research and development to improve the security of applications and files on the Internet and thus to prevent malicious use.

Downloadable files over the Internet are often the target of attacks on the Internet. As thousands and thousands of people download these files regularly, it becomes especially important to protect such files.

In this article, we will learn about checksums and how they can be used to authenticate a downloaded file from the Internet.

What is a SHA256 Checksum?

A Checksum is a cryptographic signature of a file. It is basically a string that uniquely represents the file; thus if a file is ‘tampered‘ with or ‘modified‘, its checksum value will change and the user will know that the file has been changed.

There are a number of mathematical algorithms for generating Checksum for a file in Linux. One such algorithm which is very popularly used is SHA256, which stands for ‘Secure Hash Algorithm 256‘ and was developed by the United States National Security Agency.

This algorithm breaks down the data of the file into small-sized parts and creates and combines the hash values for each part to create the checksum value. The SHA256 Checksum is usually provided in a text file or directly as a string along with the main file, in its download section on the Internet.

Verifying SHA256 Checksum of a File in Linux

Let’s take an example of Ubuntu Groovy (20.10) ISO file download and try to verify its checksum. Note that along with the ISO files, the text file ‘SHA256SUMS‘ is provided which contains the checksum values.

Download Ubuntu File with Checksum

Download the ISO file for Ubuntu 20.10 desktop and the file SHA256SUMS in the same folder and go to the folder where they are downloaded.

To generate a checksum of the ISO file, run the following:

Generate Checksum of Downloaded File

To compare the checksum to the value in the file SHA256SUMS, run the command with the ‘-c’ flag. This will take all the checksums in the file, compare them with the corresponding filename, and print the filename that matches the checksum.

Compare Checksum of File with SHA256SUMS

As seen above, the ISO file matches the original checksum, and hence we can be sure that the file was not modified or tampered with in any way during the download.

Читайте также:  Зачем нужен центр сертификации windows

The other output is regarding the 2nd checksum in the file: for the live server ISO file which is not downloaded and hence the command prints those errors.

Conclusion

Today we learned how to verify the sha256 checksum of a file in Linux. Make sure you check out the manual page of sha256sum (by running ‘man sha256sum‘) to learn more in-depth about the command.

Thanks for reading and let us know your thoughts or questions in the comments below!

Источник

Generating a SHA-256 hash from the Linux command line

There are plenty of ways to generate a hash on any operating system, but when we talk about generating an almost-unique and fixed size bit hash, then nothing can replace the SHA algorithm.

Before making use of the Linux command to generate a SHA-256 hash, we must know what SHA actually is and what it is good for.

SHA-256 in very simple terms is a cryptographic hash function that has a digest length of 256 bits. It is an algorithm on its own that is able to generate an almostunique and fixed size 256-bit(32-byte) hash. It is also good to know that this algorithm was actually developed by the NSA (National Security Agency).

Now that we know a little bit about what SHA256 means, let’s explore a simple case where we will print a random hash function that is generated using the SHA256 algorithm against a string value.

Example

Consider the example shown below −

If we use the SHA256 algorithm on the above string and convert it into a hash we will get the following output −

This might look very interesting at first, and it surely is.

Now, let’s explore two examples where we will learn how we can generate a SHA256 hash on the linux command line.

In the first case, we will make use of the command shown below −

Output

In the second example, we can remove the openssl and the dgst command and just write the sha256sum command and we will have our hash function generated like above.

Consider the example shown below −

Command

Output

We can use either of these approaches as they more or less have the same effect on your operating system.

Источник

Как зашифровать sha256 все строки из файла?

Здравствуйте. Есть текстовый файл с множеством строк. Нужно каждую строку перевести в формат sha256. Как это лучше сделать?

Спасибо. А нельзя ли это как-то через пайп передавать другой программе? Типа: cat file.txt | sha256sum | программа

Вместо cowsay — любая другая программа.

Открываешь файл в GTKHash и вуаля.

Почему-то выдает только 1 хэш:

# cat 1key.txt | while IFS= read -r var; do echo «$var» | sha256sum; done 1857017c9249136e642e23f3ca500d45391437907c9e6dc3f7ff5f60f1d9d362 —

# while IFS= read -r var; do echo «$var» | sha256sum; done ( 16.08.17 22:26:25 )

А строк в файле 1key.txt точно не одна?

Да, там 2 строчки для теста.

И хэш не соответствует ни одной из них.

можешь показать свой cat 1key.txt ?

Спасибо, все работает. Строк показывало 1 почему-то. Последнюю строку не учитывало.

Работает, но выдает не тот хэщ 🙂 Может там знак переноса строки учитывается или еще что.

Например у слова «pizza» правильный хэш — 9ed1515819dec61fd361d5fdabb57f41ecce1a5fe1fe263b98c0d6943b9b232e

Источник

Оцените статью