>_ IzzyLab

Hands-on task

This task is step 14 of the course “Linux server security”

Encrypt a file with openssl

medium~7 min

/root/secret.txt holds a secret, and /root/enc.pass holds the encryption password. Encrypt secret.txt symmetrically into /root/secret.enc: algorithm AES-256-CBC, key derivation via PBKDF2 with 200000 iterations, the password taken from the file enc.pass (don't type it into the command: it would end up in the shell history and in the process list). Afterwards delete the plaintext secret.txt.

What you'll practise:
  • openssl
  • symmetric encryption
  • aes-256-cbc
  • pbkdf2
  • -pass

Topic breakdown

Symmetric encryption uses one password for both encrypting and decrypting; in openssl this is handled by the enc subcommand. The algorithm (AES-256 in CBC mode) and the key-derivation method (PBKDF2 — the password is run through a hash many times to make brute-forcing harder) are enabled by separate flags; without the PBKDF2 flag openssl falls back to a weak, outdated method. The password is conveniently passed non-interactively via -pass with the pass: source; the salt in this mode is added automatically. It's worth checking yourself with the reverse operation — the same call with the decrypt flag -d, where the algorithm and key-derivation method must match.

What's checked

  1. the file /root/secret.enc is created
  2. the file decrypts with the password from enc.pass using the required parameters
  3. the plaintext secret.txt is deleted

What it looks like