Sha 256 hash linux

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.

$ wget http://releases.ubuntu.com/groovy/ubuntu-20.10-desktop-amd64.iso $ wget http://releases.ubuntu.com/groovy/SHA256SUMS $ cd ~/Downloads

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

$ sha256sum ubuntu-20.10-desktop-amd64.iso

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.

Читайте также:  Загрузочная флешка linux deepin

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.

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 an SHA-256 Hash From Command Line

As technology becomes increasingly integrated into our daily lives, security concerns continue to grow. It’s more important than ever to ensure that our data is secure and protected from cybercriminals. One way to help protect data is to use a hash function. SHA-256 is one such hash function that can be used to create a unique digital fingerprint for data. In this article, we’ll explore how to generate an SHA-256 hash from command line.

What is SHA-256?

SHA-256 is a cryptographic hash function that takes input data and produces a fixed-length output, or hash, of 256 bits. function is designed to be one-way, meaning that it is easy to compute hash of some input data, but it is virtually impossible to determine input data from hash. This property makes SHA-256 useful for ensuring integrity of data and detecting any changes made to it.

SHA-256 is widely used in security applications, including digital signatures, password storage, and message authentication. It is also used in cryptocurrencies, such as Bitcoin, to secure transactions and ensure that no one can tamper with transaction data.

Generating an SHA-256 hash from command line

Generating an SHA-256 hash from command line is a straightforward process. You can use a variety of tools and programming languages to generate a hash, but we’ll focus on using command line to keep things simple.

Here are steps to generate an SHA-256 hash from command line −

  • Open a terminal or command prompt.
  • Navigate to directory where file you want to hash is located. For example, if file is on your desktop, you would navigate to desktop directory.
  • Enter command to generate SHA-256 hash. command syntax will depend on tool or programming language you’re using. We’ll cover a few examples below.

Let’s take a closer look at some examples of how to generate an SHA-256 hash from command line.

Using OpenSSL

OpenSSL is a popular open-source tool that provides a suite of cryptographic functions, including SHA-256. To use OpenSSL to generate an SHA-256 hash, follow these steps −

  • Open a terminal or command prompt.
  • Navigate to directory where file you want to hash is located.
  • Enter following command −
Читайте также:  Окно выбора операционной системы линукс

Replace «filename» with name of file you want to hash. For example, if file is called «document.txt,» command would be −

openssl sha256 document.txt

Press enter. SHA-256 hash of file will be displayed in terminal window.

Using sha256sum command

Many Linux distributions come with sha256sum command pre-installed. This command calculates SHA-256 hash of a file and compares it to a known hash value to verify its integrity. Here’s how to use sha256sum command −

  • Open a terminal.
  • Navigate to directory where file you want to hash is located.
  • Enter following command:sha256sum filename

Replace «filename» with name of file you want to hash. For example, if file is called «document.txt,» command would be −

Press enter. SHA-256 hash of file will be displayed in terminal window.

Using PowerShell

If you’re using a Windows operating system, you can use PowerShell to generate an SHA-256 hash. Here’s how −

  • Open PowerShell.
  • Navigate to directory where file you want to hash is located.
  • Enter following command −
Get-FileHash filename -Algorithm SHA256 | Select-Object Hash

Replace «filename» with name of file you want to hash. For example, if file is called «document.txt,» command would be −

Get-FileHash document.txt -Algorithm SHA256 | Select-Object Hash

Press enter. SHA-256 hash of file will be displayed in PowerShell window.

Verifying integrity of a file with SHA-256

One of main use cases for SHA-256 is verifying integrity of a file. By comparing hash of a file with a known hash value, you can determine whether file has been tampered with or corrupted.

To verify integrity of a file with SHA-256, follow these steps −

  • Obtain known SHA-256 hash value of file. This value can be obtained from a trusted source, such as website where file was downloaded from or author of file.
  • Generate SHA-256 hash of file using one of methods described above.
  • Compare generated hash with known hash value. If two values match, file has not been tampered with or corrupted.

In addition to methods described above, there are several other tools and programming languages you can use to generate an SHA-256 hash. Here are a few additional examples −

Using Python

Python is a popular programming language that has built-in support for SHA-256. Here’s how to generate an SHA-256 hash of a file using Python −

  • Open a terminal or command prompt.
  • Navigate to directory where file you want to hash is located.
  • Enter following command −
python -c "import hashlib;print(hashlib.sha256(open('filename','rb').read()).hexdigest())"

Replace «filename» with name of file you want to hash. For example, if file is called «document.txt,» command would be −

python -c "import hashlib;print(hashlib.sha256(open('document.txt','rb').read()).hexdigest())"

Press enter. SHA-256 hash of file will be displayed in terminal window.

Using sha256 command in macOS

If you’re using a macOS operating system, you can use built-in sha256 command to generate an SHA-256 hash. Here’s how −

  • Open a terminal.
  • Navigate to directory where file you want to hash is located.
  • Enter following command −
Читайте также:  Linux посмотреть параметры процессора

Replace «filename» with name of file you want to hash. For example, if file is called «document.txt,» command would be −

Press enter. SHA-256 hash of file will be displayed in terminal window.

Using CertUtil command in Windows

Windows also has a built-in command for generating SHA-256 hashes called CertUtil. Here’s how to use CertUtil to generate an SHA-256 hash −

  • Open a command prompt.
  • Navigate to directory where file you want to hash is located.
  • Enter following command −
CertUtil -hashfile filename SHA256

Replace «filename» with name of file you want to hash. For example, if file is called «document.txt,» command would be −

CertUtil -hashfile document.txt SHA256

Press enter. SHA-256 hash of file will be displayed in command prompt window.

Conclusion

SHA-256 is a powerful hash function that can be used to generate a unique digital fingerprint for data. By using command line, you can easily generate an SHA-256 hash of a file and verify its integrity. examples provided in this article should give you a good starting point for working with SHA-256 on command line.

Remember that while SHA-256 is a powerful tool, it’s important to use it in conjunction with other security measures to protect your data. Always be sure to use strong passwords, keep your software up to date, and practice safe browsing habits to help keep your data secure.

Источник

Generate and Verify SHA-256 Hash of File in Linux

Generate and Verify SHA-256 Hash of File in Linux

SHA-256 is a cryptographic hash function that can be used for verifying file integrity. For example, to check that the file has not been altered during transfer over the network. This tutorial provides example how to generate and verify SHA-256 hash of file in Linux.

Generate SHA-256 hash

In order to test, create a new file:

printf 'Hello world' > test.txt

Linux provides sha256sum command to generate and verify SHA-256 hash. Run the following command to generate SHA-256 hash of file and print result in the terminal:

64ec88ca00b268e5ba1a35678a1b5316d212f4f366b2477232534a8aeca37f3c test.txt

Result can be written to a file by using > redirection operator:

sha256sum test.txt > test.sha256

Verify SHA-256 hash

File integrity can be verified using -c option:

Change content of a file by appending additional text:

We get the following output when SHA-256 hash of a file was verified again:

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

Clear APT Cache

APT package manager allows to install packages on Debian, and Debian-based Linux distributions. APT store.

Install GitLab CE Inside Docker Container in Linux

GitLab is an open-source DevOps platform which provides Git repositories management, continuous integration, issue tracking.

Install Matchering Inside Docker Container in Linux

Matchering is a web-based application for audio matching and mastering. It uses algorithms to analyze.

Источник

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