Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GPG encryption and decryption of a folder using command line [closed]

Tags:

man page of gpg command line (Gnupg) has commands to encrypt and decrypt files. Here is a standard command to encrypt/decrypt files with gpg.

gpg --encrypt --recipient [email protected] ~/xxx/xxx.txt - to encrypt

gpg --output ~/xxx/xxx.txt --decrypt ~/xxx/xxx.gpg - to decrypt

But if i have a folder with multiple files and folders, how can i encrypt it with command line?

like image 638
0928e8f6 Avatar asked Feb 23 '16 17:02

0928e8f6


People also ask

What command can be used to encrypt decrypt files from the command line?

A command line utility, CIPHER. EXE, can be used to encrypt and decrypt files from the command line. /E Encrypts the specified directories. Directories will be marked so that files added afterward will be encrypted.


2 Answers

Solution 1:

Use gpg-zip.

Encrypt the contents of directory mydocs for user Bob to file test1:

gpg-zip --encrypt --output test1 --gpg-args  -r Bob mydocs

List the contents of archive test1:

gpg-zip --list-archive test1

This is an example directly from Encrypt or sign files into an archive. If you read that page in detail it will help you out a lot.

Solution 2:

Turn a directory into a file

If you want to encrypt a directory, you will need to convert it to a file first. Run the command:

tar czf myfiles.tar.gz mydirectory/

This gives you a new file 'myfiles.tar.gz' which you can then encrypt/decrypt. To turn a tarball back into a directory:

tar xzf myfiles.tar.gz

now you can use encrypt in the same way that you have above. So:

gpg --encrypt --recipient [email protected] ~/xxx/xxx.txt

This is taken directly from an example on berkeley encrypting, which is also a quick and useful read.

You can review the man page here: gnu gpg man

like image 146
Caleb Adams Avatar answered Sep 18 '22 12:09

Caleb Adams


gpgtar is another option as well. gpgtar encrypts or signs files into an archive. It is a gpg-ized tar using the same format as used by PGP's PGP Zip.

It installs along with gnupg on MacOS and Linux.

Encrypt Directory

gpgtar --encrypt --output <out_file_name> -r <recipient> <dir_name>

Decrypt Directory

gpgtar --decrypt <out_file_name>

gpgtar man page

like image 28
captam3rica Avatar answered Sep 16 '22 12:09

captam3rica