Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

What's the most popular command to do such things as encrypting a file or directory in terminal in Linux?

share|improve this question

I think it would be gpg. The syntax for files and directories differs though.

Encryption

For files(outputs filename.gpg):

gpg -c filename

For dirs:

gpg-zip -c -o file.gpg dirname

Decryption

For files(outputs filename.gpg):

gpg filename.gpg

For dirs:

gpg-zip -d file.gpg

Edit: Corrected as @Mk12 pointed out the mistake of compression/decompression for encryption/decryption.

share|improve this answer
    
Shouldn't that be "Encryption" and "Decryption"? – Mk12 Jul 27 '12 at 18:41
    
Thanks @Mk12. I must have been distracted to the utmost. :P – celebdor Aug 22 '12 at 15:27
    
Nobody has said how to encrypt a directory. – chovy Oct 18 '14 at 8:50
1  
@chovy Not that above it says: For dirs: gpg-zip -c -o file.gpg dirname – celebdor Oct 20 '14 at 10:33
    
@celebdor missed that one. thanks. edit: that doesn't work for me. I get some weird encrypted output when I decrypt the file. – chovy Oct 24 '14 at 15:29
  • with openssl

openssl des3 -salt -in unencrypted-data.tar -out encrypted-data.tar.des3

Decrypt:

openssl des3 -d -salt -in encrypted-data.tar.des3 -out unencrypted-data.tar

  • encrypt with AES

aescrypt -e -p password file.jpg

Decrypt:

aescrypt -d -p password file.jpg.aes

share|improve this answer
1  
+1 for showing how to do it with openssl, which is most likely available out-of-the-box. – DevSolar Aug 22 '12 at 15:39

Try GnuPG.

To encrypt: gpg -c filename

To decrypt: gpg filename.gpg

share|improve this answer

I personally use aescrypt mostly.

      aescrypt -e "File" 

and decrypt:

      aescrypt -d "File"

Or there's mcrypt:

      mcrypt "File" 

and decrypt:

      mcrypt -d "File"

And for a file, I suggest tar'ing the dir, and encrypting that. Then after unencrypting, just untar the file:

      tar -cf "Dir.tar" Dir/

and to untar

      tar -xf "Dir.tar"
share|improve this answer

This is my method using openssl and tar

Open Encrypted Directory:

openssl enc -aes-256-cbc -d -in ~/vault.tar.gz.dat | tar xz; thunar ~/vault

Lock Encrypted Directory:

tar cz vault/ | openssl enc -aes-256-cbc -out ~/vault.tar.gz.dat; rm -r ~/vault
share|improve this answer
    
rm -r does not delete data; it merely unlinks it. You'll need to use something like srm to erase the data from the disk. – jbindel May 19 at 2:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .