On Linux, sha256sum filename generates a standard SHA-256 checksum for the exact file bytes. For literal text, use printf %s 'text' | sha256sum so the shell does not append a newline.

The sha256sum command prints the digest as 64 lowercase hexadecimal characters followed by the filename. SHA-256 operates on bytes rather than abstract characters, which means an added newline, different character encoding, or a pasted version of a file can produce another result. A browser workflow is useful when the same digest must also be copied as standard Base64 or checked against a reference generated from UTF-8 text.

generate sha256 hash linux
Generate SHA256 Hash in Linux: Files and Text

Generate a file hash in Linux

  1. Open a terminal and move to the directory containing the file. For example, run cd /path/to/download.
  2. Enter the filename exactly as it appears on disk and run sha256sum payload.tar.gz.
  3. Read the first field in the output. It contains 64 lowercase hexadecimal characters representing the file's 256-bit SHA-256 digest.
  4. Compare every character with the expected checksum published by the file's owner or supplied through an authenticated release channel.
  5. If the owner provides a compatible checksum file, run sha256sum -c checksums.sha256 from the directory containing the referenced files. A successful check confirms that the current bytes match the digest recorded in that file.

A checksum file stored beside a download is not automatically trustworthy. If an attacker can replace both the downloaded artifact and its checksum, the comparison will validate the attacker's pair. Obtain the expected digest from the owner over HTTPS, through a signed release, or through another authenticated channel appropriate to the risk.

Hash exact text without changing its bytes

Linux shells and browsers can receive different byte sequences for text that looks identical on screen. The browser generator encodes text mode as UTF-8, so accents, emoji, and other non-ASCII characters may occupy multiple bytes. For a closer explanation of this distinction, see Generate SHA256 Hash From String: Byte-Exact Results.

For an ASCII or UTF-8 shell literal without a trailing newline, use:

printf %s 'hello' | sha256sum

To include one Linux line-feed byte at the end, use:

printf '%s\n' 'hello' | sha256sum

These commands differ only in whether the final line-feed byte is present, yet they hash different inputs. A common echo command also appends a newline, which is a frequent reason a command-line result differs from a value entered into a browser field.

When the text already exists in a file and you need every stored byte, hash the file rather than pasting or retyping it:

sha256sum < message.txt

This reads the file through standard input without decoding it as text. The result still depends on the file's actual encoding, line endings, normalization form, spaces, and final newline. Ensure the shell literal and the browser field contain the same UTF-8 bytes before expecting their digests to match.

Verify a download against a trusted reference

Start by obtaining the expected SHA-256 digest independently from the download itself. Then calculate the local file digest with sha256sum ./payload.tar.gz and compare the complete 64-character value. Do not rely on a matching prefix; the full digest must agree.

If the vendor publishes a standard checksum file, place it beside the artifact and run sha256sum -c vendor-checksums.sha256. The checksum file must use the expected digest and the same filename or path that the command resolves. If it fails, confirm that the correct artifact is present and that the file was not converted, unpacked, or edited in a way that changed its bytes.

For a downloaded archive, hashing the archive verifies the archive as received. It does not separately verify every extracted file. Extract only after the archive matches an authentic expected digest, and preserve the extracted files when you need to compare their own checksums.

Cross-check a Linux result in the browser

The SHA256 Hash Generator hashes UTF-8 text or local file bytes in the current browser tab and does not upload the selected content. It supports files up to 100 MB and presents the same 32-byte digest as 64 lowercase Hex characters and standard padded Base64.

  1. Select text mode or file mode according to the input you want to verify.
  2. For text mode, enter the exact string. For file mode, select the local file whose bytes should be hashed.
  3. Generate the SHA-256 value.
  4. Copy the Hex or Base64 representation required by the other system.
  5. Compare the complete output with the Linux result or authenticated reference, and confirm that both sides used the same bytes and representation.

Text mode first encodes the entered string as UTF-8, and the displayed byte count provides useful context when diagnosing a mismatch. File mode does not decode the file: it hashes every selected byte, including headers, embedded metadata, and line-ending bytes. Those distinctions explain why pasting the visible contents of a binary file into text mode will not reproduce its file digest.

Match the expected digest format

Representation Exact form Typical use
Hex 64 lowercase hexadecimal characters representing the 32 digest bytes Linux checksum files, manifests, build instructions, and vendor references
Base64 Standard padded Base64 encoding of the same 32 digest bytes Systems whose interface explicitly requests Base64

The Linux sha256sum output is Hex, so copy the Hex field when that is what the workflow expects. If another system requests Base64, use the generator's standard Base64 output instead of converting the result by eye. Correct Base64 represents the 32 raw digest bytes; it is not Base64 of the 64-character hexadecimal text.

Hex letter case changes only the presentation, not the underlying digest bytes. Nevertheless, copying the exact expected format reduces the chance of an application rejecting an otherwise equivalent value.

Diagnose a hash mismatch

Possible cause What to check
Trailing newline Compare printf %s with printf '%s\n', and check whether the browser field or source file ends with a line break.
Character encoding Confirm that both systems hashed UTF-8 bytes. Accented letters, emoji, and other non-ASCII characters can use multiple bytes.
Unicode normalization Strings that look the same can contain different normalization forms, producing different UTF-8 sequences.
File versus pasted text Headers, metadata, and binary content disappear when file contents are pasted into text mode; pasted spaces normally remain, while pasted line endings may be normalized. Spaces and line-ending bytes can change the digest.
Different representation Check whether one value is Hex and the other is Base64, and compare complete values rather than prefixes.

Also confirm that both commands referenced the same path and that no editor, transfer process, archive extraction step, or line-ending conversion altered the file. Recalculate from the final bytes instead of trying to repair the digest text.

Know what SHA-256 proves

SHA-256 is a one-way hash defined in NIST FIPS 180-4. It maps an input byte sequence to a fixed 256-bit digest. It is useful for checking whether two artifacts match, comparing a download with a vendor's checksum, or producing a value required by a build and deployment workflow.

SHA-256 is not encryption. There is no encryption key, and no supported operation reverses the digest into the original input. A matching digest also does not establish who created an artifact. When two systems share a secret and need message authentication, they should use HMAC-SHA-256. When a verifier must establish origin through a public key, a digital signature is the appropriate mechanism.

Do not store passwords by applying SHA-256 directly. Its speed is useful for integrity checks, but it also helps attackers test password guesses. Account systems should use a unique salt and a purpose-built password hashing function with calibrated memory and time costs. The browser generator intentionally performs only the raw standard SHA-256 digest.

Handle empty input and large files correctly

Empty text is valid input because the empty byte sequence has a legitimate standard SHA-256 digest, beginning with e3b0c442. Spaces, carriage returns, final newlines, and Unicode normalization choices are also part of the input and can change the result.

The browser generator accepts exact UTF-8 text or local file bytes up to 100 MB. Its Web Cryptography digest interface receives the complete byte buffer rather than streaming the data, so much larger files should be handled with a trusted streaming tool on the local machine. For Linux files beyond the browser limit, continue using the native sha256sum workflow or another established local utility and compare its complete Hex output with the authentic reference.

If you're weighing options, SHA512 Hash Generator: A Byte-Level Guide covers this in detail.