GPG

Page content

PGP and GPG

  • PGP - Pretty Good Privacy
  • GPG - GNU Privacy Guard oder GnuPG

https://en.wikipedia.org/wiki/Pretty_Good_Privacy

The Free Software Foundation has developed its own OpenPGP-compliant program called GNU Privacy Guard (abbreviated GnuPG or GPG).

Install GPG on MacOS

Installing homebrew first

Refer to https://blog.ghostinthemachines.com/2015/03/01/how-to-use-gpg-command-line/

And install it.

brew install gnupg

Use GPG

keygen

Generate a key pair

gpg --gen-key 
Real name: My Realname
Email Address: foo@bar.com
(Okay)
(Enter the pass)

As a default, the key type is RSA 2048. If you want to more secure cryptographic parameter, follow the next step.

gpg --full-generate-key
RSA and RSA
4096
0 (=not expire)
Real name: My Realname
Email address: foo@bar.com
Comment: blabla

Show keys

# Check public key list 
gpg --list-keys

/Users/atlex/.gnupg/pubring.kbx
-------------------------------
pub   rsa4096 2020-03-12 [SC]
      Your public key will shown here. I editted this line.
uid           [ultimate] My Realname (The purpose of this key is sharing credentials with members.) <foo@bar.com>
sub   rsa4096 2020-03-12 [E]

# Check private key list
gpg --list-secret-keys

/Users/atlex/.gnupg/pubring.kbx
-------------------------------
sec   rsa4096 2020-03-12 [SC]
      Your private key will shown here. I editted this line.
uid           [ultimate] My Realname (The purpose of this key is sharing credentials with members.) <foo@bar.com>
ssb   rsa4096 2020-03-12 [E]

Delete the Key

Delete publickey first. <– need to be check.

gpg --delete-key {key-ID}
gpg --delete-secret-key {key-ID}

Exporting a public key

gpg --armor --export foo@bar.com

The location the key stored is under /Users/atlex/.gnupg/ as a default.

Exporting a private key

gpg --list-secret-keys
/home/atlex00/.gnupg/pubring.kbx
--------------------------------
sec   nistp521 2021-04-01 [SC]
      1234567890ABCDEFGHIYKLMNOPQRSTUVWXYZ1234
uid           [ultimate] Firstname Lastname (Some comments) <foo@bar.com>
ssb   nistp521 2021-04-01 [E]

gpg --export-secret-keys 1234567890ABCDEFGHIYKLMNOPQRSTUVWXYZ1234 > gpg_private.key

gpg ---import gpg_private.key

Encrypting a file with the public key

gpg -e -r {email address of Pubkey} -o {output_file_name} {secret_file_name}

Decrypting a file

You need the password for encryption.

gpg -d {encrypted_file}
#or
gpg -d -o {output_file_name} {encrypted_file}

Import a public key

gpg --import keyfile.key

Trouble shootings

In WSL, IPC connect call failed

gpg: can’t connect to the agent: IPC connect call failed

How to solve (not solved so far).

https://phpsolved.com/gpg-cant-connect-to-the-agent-ipc-connect-call-failed/

$ sudo apt remove gpg
$ sudo apt install gnupg1
$ gpg --list-keys

Command 'gpg' not found, but can be installed with:

$ sudo apt install gpg