Sunday, 6 October 2019

ubuntu - How to password protect gzip files on the command line?


I want to create some tar.gz (and possibly tar.bz2) files, using the tar command on Ubuntu 10.04.


I want to password protect the file.


What is the command to do this (I have Googled, but found nothing that shows how to create and extract compressed files using a password).


Anyone knows how to do this?



Answer



you have to apply the unix-philosophy to this task: one tool for each task.


tarring and compression is a job for tar and gzip or bzip2, crypto is a job for either gpg or openssl:


Encrypt


 % tar cz folder_to_encrypt | \
openssl enc -aes-256-cbc -e > out.tar.gz.enc

Decrypt


 % openssl enc -aes-256-cbc -d -in out.tar.gz.enc | tar xz

Or using gpg


 % gpg --encrypt out.tar.gz

the openssl-variant uses symetric encryption, you would have to tell the receiving party about the used 'password' (aka 'the key'). the gpg-variant uses a combination of symetric and asymetric encryption, you use the key of the receiving party (which means that you do not have to tell any password involved to anyone) to create a session key and crypt the content with that key.


if you go the zip (or 7z) route: essentially that is the same as the openssl-variant, you have to tell the receiving party about the password.


No comments:

Post a Comment

How can I VLOOKUP in multiple Excel documents?

I am trying to VLOOKUP reference data with around 400 seperate Excel files. Is it possible to do this in a quick way rather than doing it m...