What Utility Can Provide Encryption and High Compression for Files on Linux and How Would You Use It?

Problem scenario
You want to use the same command for encryption and compression. You want the compression to be high (for maximum data density for backups and storage purposes). You can install a new package. What should you do?

Use 7zip.

Try whereis 7z to see if 7zip is installed. If it is not, install 7zip.

If you are using Debian or Ubuntu Linux, run this: sudo apt-get -y install p7zip-full

If you are running Linux SUSE, run this: sudo zypper -n install p7zip

If you are using CentOS or Fedora, run these three commands:

curl -s https://www.mirrorservice.org/sites/dl.fedoraproject.org/pub/epel/7/x86_64/Packages/p/p7zip-16.02-10.el7.x86_64.rpm > /tmp/p7zip-16.02-10.el7.x86_64.rpm

curl -s https://www.mirrorservice.org/sites/dl.fedoraproject.org/pub/epel/7/x86_64/Packages/p/p7zip-plugins-16.02-10.el7.x86_64.rpm > /tmp/p7zip-plugins-16.02-10.el7.x86_64.rpm

sudo rpm -i /tmp/p7zip-plugins-16.02-10.el7.x86_64.rpm /tmp/p7zip-16.02-10.el7.x86_64.rpm

Use tar before you use 7zip if you want to retain the user and group of the files that will be compressed. The 7z man page says " DO NOT USE the 7-zip format for backup purpose on Linux/Unix because : - 7-zip does not store the owner/group of the file."

If you do not need to retain the user and group associated with the file named goodfile and you want to create a compressed copy of it that is encrypted called good.7z, run this command:

7z a -p -mx=9 -mhe -t7z good.7z goodfile

We find the 7zip excels in the compression ratio compared to the zip utility.

You can move a copy to a different directory, then run this command to extract a regular version of this file that was encrypted and compressed in good.7z:
7z e good.7z

If you only need to encrypt, see this external page for examples of different tools. (However, beware of drawbacks of GPG and openssl. This external posting provides some relevant warnings.)

If you only need to compress, see this external page for examples of different tools.

Leave a comment

Your email address will not be published. Required fields are marked *