Skip to content

Instantly share code, notes, and snippets.

@ekreutz
Created June 17, 2024 11:28
Show Gist options
  • Save ekreutz/8890bd7a815c77c69d823eca50182bd6 to your computer and use it in GitHub Desktop.
Save ekreutz/8890bd7a815c77c69d823eca50182bd6 to your computer and use it in GitHub Desktop.
Using encrypted 7z archives (Ubuntu, zip, 7zip)

Using 7zip to create encrypted archives

Let's use 7zip for strong AES256 encrypted archives with a password. The guide assumes you're on Ubuntu 22 or newer. Note: this creates .7z archives, which is not the same as the regular .zip!

# Install 7zip. Note: don't install "p7zip-full" or "p7zip" (it's an older version!)
# Source, version things: https://askubuntu.com/questions/1465853/difference-between-several-command-line-tools-provided-for-7-zip-compression-li
sudo apt update
sudo apt install 7zip

# --> Version used here
7z --help

7-Zip 23.01 (x64) : Copyright (c) 1999-2023 Igor Pavlov : 2023-06-20
64-bit locale=en_US.UTF-8 Threads:18 OPEN_MAX:1024

# --> Create encrypted archive with sensible defaults (-p makes it ask for a password)
# The command works recursively on subfolders, too.
7z a \
  -t7z -m0=lzma2 -mx=9 -mfb=64 \
  -md=32m -ms=on -mhe=on -p \
   archive_name.7z ./my_folder

# --> Extract the archive to a non-existing output folder my_output (created when this is run)
7z x archive_name.7z -o./my_output

Bonus, view technical specs of archive:

# Command to check specs
7z l -slt archive_name.7z                                                                                                 Py sleepy


7-Zip 23.01 (x64) : Copyright (c) 1999-2023 Igor Pavlov : 2023-06-20
 64-bit locale=en_US.UTF-8 Threads:18 OPEN_MAX:1024

Scanning the drive for archives:
1 file, 943200 bytes (922 KiB)

Listing archive: archive.7z

Enter password (will not be echoed):  # <- you need to enter password again, here

--
Path = archive_name.7z
Type = 7z
Physical Size = 94320
Headers Size = 832
Method = LZMA2:1536k 7zAES     # <- 7zAES means AES256 encryption
Solid = +
Blocks = 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment