Advertisement
Tech

Linux Command Line: gpg

GPG is the open source alternative to PGP. GPG and PGP are cryptographic software packages that encrypt and decrypt files to ensure security on a computer. In this entry to the Brighthub Linux Command Line series you will learn the basics of encrypting a file with GPG.

By jlwallen
Desk Tech
Reading time 2 min read
Word count 407
Linux Computing Linux commands
Linux Command Line: gpg
Advertisement
Quick Take

GPG is the open source alternative to PGP. GPG and PGP are cryptographic software packages that encrypt and decrypt files to ensure security on a computer. In this entry to the Brighthub Linux Command Line series you will learn the basics of encrypting a file with GPG.

On this page

Generating a key

Before you can do anything with GPG you need to generate a passkey. This key will allow you to encrypt and decrypt files. To generate your key enter the command:

gpg –gen-key

Advertisement

You will be asked a few questions during this process. The first question is:

Please select what kind of key you want:

Advertisement

(1) DSA and Elgamal -This is the default option.

Basic Usage

I am going to assume that GPG is already installed on your computer.

Advertisement

With that in mind, let’s take a look the commands you need to encrypt and decrypt any file using GPG. To encrypt a file the command structure is;

gpg [OPTIONS] recipient filename

Advertisement

For simplicity I am going to show you how to encrypt a file for your own personal use. This means that only you, or anyone who has your personal gpg keyphrase working on your machine, can un-encrypt the file.

In this case the recipient name will be your personal username you use on your Linux machine. So the actual comand to encrypt a file will be:

Advertisement

gpg –encrypt –recipient ‘USERNAME’ filename

This will create a new file called filename .gpg

Advertisement

To decrypt the file use the command:

gpg –output filename –decrypt filename.gpg

Advertisement

When you encrypt a file you will not be asked for your passphrase.

When you decrypt a file you will be asked for the passphrase used when you create your key.

Advertisement

Final Thoughts

GPG is an outstanding tool to aid in your quest for a highly secure computer experience. But don’t limit your gpg experience to encrypting files. You can expand gpg for email encryption and other types of encryption. There are thunderbird extensions that allow you to integrate gpg for simple email encryption. GPG is very flexible and very powerful. Get to know gpg and the many things it can do for you.

This post is part of the series: Keep your Linux box secure with these tools

Linux is well known for its security. It’s one of the many reasons why IT managers insist on using Linux to keep data safe. But do you know the tools to keep your Linux boxes security as high as possible? This Bright Linux Commands series will introduce you to the tools you need to keep Linux secure

Advertisement
  1. Know your Linux security tools
  2. Linux Command Line: ssh
  3. Linux Command Line: gpg
  4. Let IPtables Help Secure Your Linux Box
  5. Linux Firewalls Made Easy With Fwbuilder
Keep Exploring

More from Tech

Filed under
Linux Computing
More topics
Linux commands
Advertisement