Ask Ubuntu is a question and answer site for Ubuntu users and developers. 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

I am new to part of encryption on Ubuntu .

Is there any way to encrypt files and folder with password from terminal ? without using truecrypt or cryptkeeper etc.

share|improve this question
up vote 9 down vote accepted

You can encrypt and decrypt files with gpg

To encrypt a file

gpg -c

To decrypt a file


But gpg will not do entire directories. For entire directories you have several options, ecryptfs is popular.

# Install if ecryptfs-utils if needed
sudo apt-get install ecryptfs-utils

# Make an encrypted directory

That will make a directory "Private". Any data you put into the directory Private will automatically be encrypted when you log out and decrypted when you log in.

If you want a different behavior or a different directory ...

mkdir ~/secret
chmod 700 ~/secret

sudo mount -t ecryptfs ~your_user/secret ~your_user/secret

Put your data into ~/secrte

To encrypt

sudo umount ~your_user/secret

To Decrypt

sudo mount ./secret ./secret -o key=passphrase,ecryptfs_cipher=aes,ecryptfs_key_bytes=16,ecryptfs_passthrough=no,ecryptfs_enable_filename_crypto=yes

Hint: make an alias for that second command.

See or man ecryptfs for additional details.

share|improve this answer
this is will help me alot thanks – twister_void Jan 25 '12 at 17:18

ecryptfs will certainly encrypt files and folders, ensuring that the data that gets written to disk is always encrypted, and that applications which need access to the cleartext context can get that seamlessly.

However, to answer your question specifically, you can certainly encrypt a single file with a passphrase and gpg:

gpg -c /tmp/file > /tmp/file.gpg

To encrypt a folder, you should use tar in conjunction with gpg:

tar zcvf - /tmp/directory | gpg -c > /tmp/directory.tar.gz.gpg
share|improve this answer
For anybody else who read this quickly and was a little confused by the result.. on 14.04 gpg -c /tmp/file > /tmp/file.gpg does not return what I'd expect, instead writing an empty file. My usage is gpg -c /tmp/file which automatically adds the .gpg extension to the resulting file. – Phil Oct 12 '15 at 14:08

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.