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 need to be able to encrypt/decrypt a single text file stored on my external HD in 12.04 LTS, preferably a GUI application, if any, or the command line otherwise. Thank you.

share|improve this question

A simple way to encrypt a single file is with openssl:

openssl des3 < youfile.txt > yourfile.txt.des3

This will prompt you for a passphrase, which you will need to enter later when decrypting the file.

openssl des3 -d < yourfile.txt.des3 > yourfile.txt.decrypted

To make this "graphical" you could put it in a Nautilus script and make it accessible from the context menu. (See the docs of Nautilus for that.)


des3 is just an example. See the list of ciphers in man openssl, under ENCODING AND CIPHER COMMANDS.

share|improve this answer
Why des3? You can do much better encryption faster with openssl aes-128-cbc – Brendan Long Jun 14 '13 at 19:46
@BrendanLong: I guess the reason is that aes-128-cbc in not mentioned in man openssl - I wonder why. It works, though. – Walter Tross Dec 21 '13 at 2:09

Lets assume that a person wants to encrypt a file called 'message.txt':

1. Encrypting a file using GPG, for personal use

I. Using a passphrase to encrypt the file (and not the private key)

I.i. The command: gpg -c message.txt does it; it asks for a password (and a password confirmation) and generates an encrypted 'message.txt.gpg', which is binary.

I.ii. If you want to generate an ASCII encrypted file, which is base64(i think) of that file, you can use gpg -c --armor message.txt This will generate an 'message.txt.asc', which is the same as the generated by the command before, but base64 coded, i.e., the encrypted file in text mode (.asc, not binary as .gpg would be).

II. Using a private key to encrypt a file

II.i. If you want to encrypt a file using your key, instead of only a passphare, use the command gpg -e -r 'yourname' message.txt. The argument 'yourname' should contain a part of the name that you used to create the private key. If you dont give the -r parameter, gpg will ask for it. You can type our name then (the same that you would type on command line).

II.ii. Point II.i would give you a binary file. If you want to get an ASCII file, use --armor. gpg -e -r 'yourname' --armor message.txt.

2. Decrypting the file encrypted with GPG

To decrypt, the file, use the command gpg -d --output OUTPUTFILE message.txt.gpg. This will ask for the passphrase and then decrypt the file message.txt.gpg to OUTPUTFILE, if the passphrase is correct. This passhrase is that which you used directly (point I., the -c parameter), or through your private key (point II., the -e parameter) This works for both binary (.gpg) or ascii (.asc) files. If you supress the --output FILE, it is outputted to console (stdout), then you can do this also, that is, redirect it to a file: gpg -d message.txt.gpg > OUTPUTFILE.txt Both do the same. 8 )

share|improve this answer

Try it works great.

share|improve this answer Is a question on a related subject. You can use the same principles for encryption if I am not mistaken.

share|improve this answer

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.