Encrypting and decrypting archives with 7-Zip (2024)

Posted: July 21, 2021 | | by Ken Hess (Sudoer alumni, Red Hat)

Image

Encrypting and decrypting archives with 7-Zip (1)

7-Zip is a free, open source, cross-platform compression and encryption utility that neither requires registration or any kind of payment to use, even in a commercial environment. It's licensed under the GNU LPGL and other licenses. It's likely that you've at least heard of 7-Zip somewhere in your travels because it's been around since 1999. I think you'll like its many features, and I'm happy to bring this little gem to light, especially if you've never used it and you're looking for an encryption solution for your backups.

[ You might also enjoy: Taming the tar command: Tips for managing backups in Linux ]

There are three vulnerability points for files and archives when transported or stored: in-use, in-flight, and at rest. This article focuses on how you can protect file archives in-flight and at rest withAES-256 encryption. Hopefully, everyone performs daily backups and follows the 3-2-1 rule of archiving and storage. But even if you do, you should encrypt your archives for safekeeping. Encryption, especiallyAES-256 encryption, helps protectyour files and archives from prying eyes, even if they're exfiltrated into a malicious actor's possession.

Don't forget that 7-Zip is also an excellent compression tool if you want to minimize those backup file sizes. But this article focuses on encryption rather than compression. There are several switches and configurations available to obtain different compression levels for your archives. Check the man page for more information on compression settings.

While 7-Zip's encryption and compression features aregood, its backup features are weak. On the man page for 7-Zip, you find the following warning:

Backup and limitations

DO NOT USE the 7-Zip format for backup purposes on Linux/Unix because 7-zip does not store the owner/group of the file. On Linux/Unix, in order to backup directories, you must use tar.

Installation

7-Zip isn't a base product, so you'll have to install it. To grab the entire suite of 7-Zip plugins and documentation along with the main 7-Zip package, use the following command:

# dnf install -y p7zip*

I use the * to download every package related to 7-Zip. This installs p7zip, p7zip-plugins, and p7zip-doc from the EPEL repository.

Encryption

Files encrypted using the .7z format are encrypted with AES-256 encryption by default. You don't need any extra settings to obtain that encryption level. You should turn on data and header encryption (-mhe=on) so that no one can see your file list in the archive file before entering the password (key). The following example is my standard one for encrypting a tarball. I don't supply any special compression switches, but I do turn on header encryption, and I always supply a strong password (encryption key) for each archive. Generically, this is my archive and encrypt command:

$ tar -cf directory.tar <directory>$ 7z a -p -mhe=on directory.tar.7z directory.tar

Here is the interactive version for a directory named archive.

$ tar -cf archive.tar archive$ 7z a -p -mhe=on archive.tar.7z7-Zip [64] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21p7zip Version 16.02 (locale=en_US.UTF-8,Utf16=on,HugeFiles=on,64 bits,1 CPU Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz (806E9),ASM,AES-NI)Creating archive: archive.tar.7zItems to compress: 1Enter password (will not be echoed):Verify password (will not be echoed) : Files read from disk: 1Archive size: 166 bytes (1 KiB)Everything is Ok$ lsarchive archive.tar archive.tar.7z 

Not all documentation on the 7-Zip utility is the most up-to-date. My suggestion is always to consult the man page, which should provide the latest information. I find the man page to be the most accurate and helpful documentation available.

The 7z format

This information is an excerpt from the 7-Zip website.

7z is the new archive format, providing a high compression ratio.

The main features of 7z format:

  • Open architecture
  • High compression ratio
  • Strong AES-256 encryption
  • Ability to use any compression, conversion, or encryption method
  • Supporting files with sizes up to 16000000000 GB
  • Unicode file names
  • Solid compressing
  • Archive headers compressing

7z has an open architecture so it can support any new compression methods.

Decryption

First, decrypt the archive from the compressed, encrypted 7z file and supply your encryption password.

$ 7z x archive.tar.7z 7-Zip [64] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21p7zip Version 16.02 (locale=en_US.UTF-8,Utf16=on,HugeFiles=on,64 bits,1 CPU Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz (806E9),ASM,AES-NI)Scanning the drive for archives:1 file, 440 bytes (1 KiB)Extracting archive: archive.tar.7zEnter password (will not be echoed):--Path = archive.tar.7zType = 7zPhysical Size = 440Headers Size = 200Method = LZMA2:12k 7zAESSolid = -Blocks = 1Everything is OkSize: 10240Compressed: 440$ lsarchive.tar archive.tar.7z

Now, untar the tarred files in the usual way.

$ tar xvf archive.tararchive/archive/file1.txtarchive/file2.txtarchive/file3.txtarchive/file4.txtarchive/file5.txtarchive/file3.old.txt

Your directories and files are intact with the proper permissions. That's all there is to it. 7-Zip's simplicity, speed, compression, and encryption make it a must-have for sysadmins who need those features for your archives.

[ Thinking about security? Check out this free guide to boosting hybrid cloud security and protecting your business. ]

Wrap up

I feel good knowing that 7-Zip is a free, open source utility that requires no fees or registration to use. It works on Windows, Linux, and Mac systems, so you should be covered on all of your platforms. Please test the encryption and decryption processto be sure that you can extract your tar files after they've been encrypted and decrypted. You certainly don't want to find out that something has gone wrong with your tar filewhen you need to restore something from one of them.

Encrypting and decrypting archives with 7-Zip (2024)
Top Articles
Hashcat tutorial for beginners [updated 2021]
The most dangerous malware of 2022
Express Pay Cspire
Pet For Sale Craigslist
Http://N14.Ultipro.com
Coverage of the introduction of the Water (Special Measures) Bill
Craigslist Motorcycles Jacksonville Florida
Puretalkusa.com/Amac
Pike County Buy Sale And Trade
Nwi Police Blotter
What is international trade and explain its types?
Oxford House Peoria Il
Cbs Trade Value Chart Fantasy Football
Guidewheel lands $9M Series A-1 for SaaS that boosts manufacturing and trims carbon emissions | TechCrunch
Nyuonsite
Aldi Süd Prospekt ᐅ Aktuelle Angebote online blättern
Imagetrend Inc, 20855 Kensington Blvd, Lakeville, MN 55044, US - MapQuest
Aaa Saugus Ma Appointment
Satisfactory: How to Make Efficient Factories (Tips, Tricks, & Strategies)
Traveling Merchants Tack Diablo 4
Leccion 4 Lesson Test
Accident On 215
Toyota Camry Hybrid Long Term Review: A Big Luxury Sedan With Hatchback Efficiency
Lisas Stamp Studio
College Basketball Picks: NCAAB Picks Against The Spread | Pickswise
Greensboro sit-in (1960) | History, Summary, Impact, & Facts
fft - Fast Fourier transform
Yale College Confidential 2027
10-Day Weather Forecast for Santa Cruz, CA - The Weather Channel | weather.com
Willys Pickup For Sale Craigslist
Craigslist Maryland Baltimore
Yoshidakins
Upstate Ny Craigslist Pets
A Man Called Otto Showtimes Near Carolina Mall Cinema
Natashas Bedroom - Slave Commands
Instafeet Login
Puretalkusa.com/Amac
Satucket Lectionary
Coffee County Tag Office Douglas Ga
Portal Pacjenta LUX MED
Scythe Banned Combos
Phmc.myloancare.com
Rise Meadville Reviews
Big Brother 23: Wiki, Vote, Cast, Release Date, Contestants, Winner, Elimination
Kushfly Promo Code
Every Type of Sentinel in the Marvel Universe
Turning Obsidian into My Perfect Writing App – The Sweet Setup
Duffield Regional Jail Mugshots 2023
Pauline Frommer's Paris 2007 (Pauline Frommer Guides) - SILO.PUB
Latest Posts
Article information

Author: Tish Haag

Last Updated:

Views: 5279

Rating: 4.7 / 5 (67 voted)

Reviews: 90% of readers found this page helpful

Author information

Name: Tish Haag

Birthday: 1999-11-18

Address: 30256 Tara Expressway, Kutchburgh, VT 92892-0078

Phone: +4215847628708

Job: Internal Consulting Engineer

Hobby: Roller skating, Roller skating, Kayaking, Flying, Graffiti, Ghost hunting, scrapbook

Introduction: My name is Tish Haag, I am a excited, delightful, curious, beautiful, agreeable, enchanting, fancy person who loves writing and wants to share my knowledge and understanding with you.