How to Password Protect Files in Linux

This short guide will explain how you can password protect files in Linux so that they’re secure from any prying eyes.

If you store important information on your Linux server and want to make sure it is for your eyes only you need to password protect these files. Let’s see how you can do this with Linux.

First, pick a good password. There are a few websites on the Internet that help you generate strong passwords. Try and pick an alphanumeric password. Something such as Rv7fkcxASW8h would be a good choice.

Now check to see if you have the package gpg installed on your computer. Run the following command to check:

# whereis gpg
gpg: /usr/bin/gpg /usr/share/man/man1/gpg.1.gz

If you get an output like the one shown above it means you have the required package installed. If not, check your Linux distribution’s documentation to see how you can install the GPG package.

Say you want to password protect a file called dbbackup.zip with the password Rv7fkcxASW8h here’s how you would go about it:

# gpg -c dbbackup.zip

When you enter this you will be requested to enter a passphrase, which is the password you want to protect the file with. Enter the password twice. Now you should see a file called dbbackup.zip.gpg in the same directory as the original file. This is the encrypted and password protected copy of the original file. You can store this file on your hard drive or ship it to someone on a DVD knowing that it will be nearly impossible for most people to crack it.

When you want to read the file you will need to remove the password protected encryption. For that execute the following command:

gpg dbbackup.zip.gpg

You will be asked to enter the password using which the file was protected. Enter that and you should be in business. Note that this only works for files and not for folders.

All in all, it’s a lot easier than the hassles you have to go through to securely store files in Windows.


If this article helped you, I'd be grateful if you could share it on your preferred social network - it helps me a lot. If you're feeling particularly generous, you could buy me a coffee and I'd be super grateful :)

buy a coffee for simplehelp.net


Home » Linux » How to Password Protect Files in Linux

1 thought on “How to Password Protect Files in Linux”

  1. Thanks a lot i was looking for this command from last week. Ultimately find it at your website.

Leave a Comment

Your email address will not be published.