GPG (GNU Privacy Guard)
Table Of Content
Definition
GPG (also known as GnuPG) stands for GNU Privacy Guard. It is a free open source version of PGP (Pretty Good Privacy) encryption software.
Create your own keys and encrypt file with it
1) Install it
On Unix
you can download gpg with the following command:
On Windows
Install the TODO
2) Create your GPG key
That is, you will generate both a private and a public key with a single command. Enter your name and email address at the prompts, but accept the default options otherwise.
You can also run it with the --full-generate-key
option if you want to have full control over the algorithm used, etc. before entering the same information that the previous command.
By doing this, you will allow people to encrypt files / messages with the public key you generated.
3) Encrypt a file
You can encrypt a file in many different ways which will served differents needs.
This will create a new encrypted file named filename.txt.gpg
. [name/group]
parameters will depends on who you want to share this file with. If you want to share to a collegue, then you should put his name here. If you want to share with you then put your name. If you want to share with both add two --recipient
for each person.
Note: This might take a couple minutes so don't loose hope.clear
Known issue: If you Pexecute this command remotly, you can log in to another shell and perform the following command in order to generate entropy needed for the generation :
Source : Stack Exchange
4) Export your public key
You can export your public key in different ways. You can either use your email adresse which if more convenient, or the GPG key ID which will correspond to a well identified key. You can find your GPG key ID by running the gpg --list-secret-keys --keyid-format LONG
command and look for this field :
Then, you're ready to run either one :
This will generate an .asc
file containing your public key. Share this file in order to allow users addind this key to their known keys.
Decrypt file with someone else public key
You can decrypt your .gpg
file by running the following command. It will print directly the ASCII text in the console for you :
So if you know this file doesn't contains ASCII, you better omit the --decrypt
option and only run this command which will save filename.txt
in your disk :
Setup with GitHub
To set your GPG signing key in Git, paste the command below, substituting in the GPG key ID you'd like to use.
You can then add the -S
option when committing in order to sign the commit :
Keep in mind you will need to provide your passphrase in that case. You can also sign tags
Bonus : Setup gpg-agent
to avoid
gpg-agent
to avoidIf you're tired of entering your passphrase everytime you do something with gpg, you should consider using the gpg-agent. Indeed it will allow you to enter it once and use it until it expire. The expiration time will be up to you.
You simply have to create the file .gnupg/gpg-agent.conf
and insert into it :
This will tell the cache to last around a year (34560000 seconds = 400 days). Like I said, it's up to you and your needs.
Useful commands
To know if you gpg-agent is running, do the following :
List all the known public keys in your keyring, as well as the name and email address associated with each key :
List all the known private keys in your keyring :
List all GPG keys for which you have both a public and private key
Create group of people to share easily. You need to add the group option in your
~/.gnupg/gpg.conf
file :
Known issues
Acknowledgements
Config links
Keep GnuPG credentials cached for entire user session - superuser
Known issues link
Last updated
Was this helpful?