Skip to content


How to password protect files in Linux

Linux Security

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 very hard and 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. You should create a zip or tar archive of the files you want to secure and then add the password protected encryption to it.

Posted in Linux, Security.

Get Simple Help tutorials just like this one in your email inbox every day - for free! Just enter your email address below:

 

You can always opt out of this email subscription at any time.

3 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. IT Buzz says

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

Continuing the Discussion

  1. | Standalone Sysadmin linked to this post on June 29, 2009

    [...] to ssh authentication. If you want to learn more about how to use it, Simple Help has a tutorial on it, covering the very basic usage. Once you’re comfortable with that, check out the [...]

  2. Password-protect files in Linux « Linux & Stuff linked to this post on July 1, 2009

    [...] in CLI, password | Tags: CLI, password Here’s a useful CLI to enable protecting special files in your system. To protect file.txt just run [...]



Some HTML is OK

or, reply to this post via trackback.