You can password-protect any type of file in Linux, which is useful if you want to store it in the cloud or carry it around in a USB stick.


With Linux, we will encrypt a file using gpg, which is part of GnuPG.

gpg -c filename.txt

Consider the following scenario: I have a file called my-personal-info.txt

gpg -c my-personal-info.txt

Upon running the command, the following output is displayed:

$ gpg -c my-personal-info.txt 
Enter passphrase:
Repeat passphrase:

gpg has now created a file called my-personal-info.txt.gpg, which has been encrypted. The original file is still there, so you may want to erase it, transport only the encrypted file, or e-mail the encrypted file.

To decrypt a file just enter this command.

gpg -d my-personal-info.txt.gpg

A new copy of the file will be created after you enter your password or passphrase. The idea of storing passwords to important sites in this way is a good one.