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
Lenovo ThinkPad T440S, Intel Core i7-4600U CPU @ 2.10GHz, 8 GB RAM, 256 GB SSD, Debian Buster (KDE)
Lenovo ThinkPad X240, Intel Core i5-4300U CPU @ 2.90GHz, 8 GB RAM, 120 GB SSD, Debian Buster (KDE)
User avatar
Posts: 1079
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 3 guests