DEV Community

Cover image for gpg command examples

Posted on

gpg command examples

gpg is a program to encrypt and decrypt files. In other words, it is a program for privacy and security.

Your data is safe if you store it on gpg (i.e. encrypted).
Your data is not safe if you don't encrypt it with gpg (i.e. not encrypted).

So why would you expose your secret information to the threat of being stolen by leaking it to a computer disk?

The only reason is ignorance, because encryption is easy and saves you effort and money in the long run.

Tools like gpg make encryption as easy as saving a file, or even easier.

gpg linux will help you encrypt your e-mails or to encrypt files on your disk so that nobody else can read them without knowing the decryption password which you alone know.

If you are new to the linux command line, you can practice here

What is encryption?

Encryption is a method for obscuring electronic data from those who should not see it.

Encrypted data is unreadable by anyone without special knowledge, often referred to as a ‘key’. With most encryption systems, the key needed to decrypt the data is unique to the individual user.

You can use gpg with a single private key or with a key pair.

The gpg program works with separate keys which are required for reading as well as writing.

The public key which is used for reading is distributed in ways that allow others to know that it really belongs to the person named in the user certificate.

The private key must be kept secret, so it is typically stored on a smartcard or similar device.


What can gpg do?

gpg is a program to encrypt and decrypt files.
gpg is intended to be correctly and completely OpenPGP compliant.

The main features of gpg are:

  • Encrypting and decrypting files with the OpenPGP file format.
  • Full integration with OpenLDAP and other applications.
  • Key generation (prime generation, digest calculation), import/export of keys,
  • Creation of revocation certificates, batch key signing, change passphrases,
  • Powers for saving private and public keys on smartcards and importing public keys from smartcards.
  • Symmetric encryption of data and special files.

gpg logo

Symmetric encrpytion

Encrypt a file with a password

gpg -c [file]
Enter fullscreen mode Exit fullscreen mode

Decrypt a file

gpg -d [file]
Enter fullscreen mode Exit fullscreen mode

Asymmetric encryption

If you want to use public/private key pairs instead.

Generate a new key pair

gpg --gen-key
Enter fullscreen mode Exit fullscreen mode

Encrypt a file to a recipient

gpg -e -r [recipient key] [file]
Enter fullscreen mode Exit fullscreen mode

List keys in local keychain

gpg --list
Enter fullscreen mode Exit fullscreen mode

There are also some gui alternatives to encryption that you can use in your file manager.

Top comments (0)