Create 7-zip encrypted archive

Installing 7-zip in Ubuntu

sudo apt install p7zip-full

This is a quick oneliner to compress and encrypt files in folder. This uses symmetric AES-256 encryption. 

    7z a \
      -t7z -m0=lzma2 -mx=9 -mfb=64 \
      -md=32m -ms=on -mhe=on -p'verysecretpassword' \
       archive.7z directoryoffiles

 

You can actually leave the password after -p switch empty and the password is asked interactively. This way it's little more secure, but can't be used in scripts because it's usually run in the background. In scripts you can replace it with command substitute or write the password in the commandline, but then remember to read protect the script. 

Quick way to disable reading of the file for others than the owner of the file

chmod 600 nameofthescript

Explanation:

Here are the switches explained

SwitchMeaning
aAdd (directoryoffiles to archive.7z)
-t7z7z format
-m0=lzma2lzma2
-mx=9Use the '9' level of compression = the best level
-mfb=64Use number of fast bytes for LZMA = 64
-md=32mUse a dictionary size = 32 megabytes
-ms=on  Solid archive = on
-mhe=on

7z format only : Disables listing of files without a password
In ZIP format you can't encrypt headers, so even without the password filenames are visible. 

-p{Password}Add a password

About AES-256 encyption.

I found this article from scrambox website and there is an explanation how the brute force times are calculated. 
Here is the re-cap from the site how long it would take the different computers to brute force this encryption

Computing powerAverage time to crack using exhaustive search
High-end PC27,337,893,038,406,611,​194,430,009,​974,922,940,​323,611,067,​429,756,962,​487,493,203 years.

27 trillion trillion trillion trillion trillion years
Fastest supercomputer27,337,893,038,​406,611,194,​430,009,974,​922,940,323,​611,067,429,​756,962,487 years.

27,337,893 trillion trillion trillion trillion years
2 billion high-end PCs13,668,946,​519,203,305,​597,215,004,​987,461,470,​161,805,533,​714,878,481 years

13,689 trillion trillion trillion trillion years
Age of the universe15,000,000,000 years

15 billion years

Comments