Encrypting a single file with GPG from the CLI

Share your own howto's etc. Not for support questions!

Encrypting a single file with GPG from the CLI

Postby Hallvor » 2015-09-22 06:39

What is GPG?
GnuPG is a complete and free implementation of the OpenPGP standard as defined by RFC4880 (also known as PGP). GnuPG allows to encrypt and sign your data and communication, features a versatile key management system as well as access modules for all kinds of public key directories. GnuPG, also known as GPG, is a command line tool with features for easy integration with other applications.

Why use encryption?
Even if you have nothing to hide, using encryption helps protect the privacy of people you communicate with, and makes life difficult for bulk surveillance systems.

Encrypting a file with a password
To encrypt a file, open a terminal in the directory of the file you want to encrypt. Encrypt the file using the command

Code: Select all
$ gpg -c thenameofmyfile

If the file you want to encrypt is called "mypasswords.odt", you can use the command:

Code: Select all
$ gpg -c mypasswords.odt

You will then be asked to enter a password twice:

Code: Select all
Enter passphrase:
Repeat passphrase:

The resulting encrypted file will then get the extension .gpg, like this: "mypasswords.odt.gpg"

Decrypting the file
To decrypt the file, use the following command:

Code: Select all
$ gpg thenameofmyfile

Like this:

Code: Select all
$ gpg mypasswords.odt.gpg

You will then be asked to enter your password. Upon entering your password, the file will be decrypted.

Several files or folders can be encrypted using the same method. Just use tar them (or whatever) to put them all into a single archive first.

See also:
http://www.cyberciti.biz/tips/linux-how ... sword.html
HP Elitebook 2570p, Intel Core i5 3320-M CPU @ 2.60 GHz, 6 GB RAM, Intel HD 4000 graphics, 240 GB SSD, Debian Stretch (KDE)
User avatar
Posts: 814
Joined: 2009-04-16 18:35
Location: Norway

Return to Docs, Howtos, Tips & Tricks

Who is online

Users browsing this forum: No registered users and 2 guests