Encrypt Your Data Files in Linux

Encrypt Data File

Are you one of the people who has countless accounts on various websites requiring you to remember all the user names and passwords? At some point, you either end up reusing the same password, which is quite dangerous to do, or you start writing down the passwords and user names to a file on your computer so that you can find them later on, which can be even more dangerous if not encrypted.

Luckily, there is a simple way to encrypt your text files containing sensitive data such as passwords, account numbers, credit card numbers, and so on. In this tutorial, I will show you how to do that in Linux Ubuntu (should work for any distribution).

1. Install GnuPG

First, we need to install GnuPG. In your shell, type:

sudo apt-get install gnupg

Once installed, locate the file containing your sensitive data. In our case, the file is called mypasswords.txt. We will now encrypt it as follows.

2. Encrypt your file with a password

Go to the directory where the file is located and issue:

gpg -c mypasswords.txt

You will be prompted to create an encryption password twice. Type it twice as you get asked. Make sure to carefully store the password (not in your computer, somewhere on a piece of paper in your apartment perhaps) as you will need it to read the content of the encrypted file.

3. Decrypt your file with a password

Once the file is encypted, it will have a .gpg extension. To simply view the content of the file, type and follow up with your password when prompted for it:

gpg -d mypasswords.txt.gpg

If you want to edit the content of the file, you first need to decrypt it to an unencrypted file, change the content and then encrypt it back. To decrypt the file, use the following command, just change the file name with yours. Make sure to remove the .gpg extension from the file name after the > character.

gpg -d mypasswords.txt.gpg > mypasswords.txt

Now you can open the mypasswords.txt file and it should contain a plain text of your sensitive data. You can change it and encrypt it back. Once encrypted, don’t forget to delete the original non-encrypted file mypasswords.txt.

You can use this technique to encrypt any kind of a file: images, MS Word documents, XML files, and so on.

Bookmark the permalink.