linux-gpg
Linux GPG
This document shows how to use the command line to work with PGP (GPG) for encryption.
Create a key pair
Use the following shell command:
Answer the prompts, I typically accept all defaults which is 2048 bits and RSA. Also memorize your long passphrase and never tell anyone it, ever.
Document your new 'KeyID'.
List all keys
This is a great way to determine a 'KeyID'
Encrypt a test message
This process may also be used to Validate a private key passphrase.
It will prompt for a passphrase three times unless a valid one is submitted, then it will allow you to write an encrypted message. press ctrl-d to end the message.
Alternatively you may encrypt any file (text or binary) using a command like this:
This will prompt for your passphrase and on success generate an 'asc' file.
For example, lets encrypt the fake test file 'secret-raw-payload.txt' using the following command:
Decrypt a test message
Then paste the encrypted message into the terminal.
Optionally omit the 'encrypted message file' and paste the payload directly into the cmd prompt.
Export a public key
To export a public key for transportation or sharing, run this:
This will output the public key for a given KeyID as ascii, which may be shared and distributed to anyone.
Export a private key
To export a private key for transportation or backup, run this:
This will output the private key for a given KeyID as ascii, which must be safely gaurded.
Import a public key
This adds the public key in the file to your public key ring. Alternatively you may omit the file and paste the public key directly to the command prompt.
Import a private key
This adds the private key in the file to your private key ring. Alternatively you may omit the file and paste the private key directly to the command prompt.
Delete a public key
Delete a private key
Edit and Trust a key
To edit a keys trust level (for instance to completely trust your own key) do the following:
Encrypt a directory
If you want to encrypt a directory instead of a file, use the gpg-zip tool:
Symmetric Keys
If you want to use a single shared key use the --symmetric flag. It will prompt you for a password twice:
- --list-archive:
-
List the contents of the specified archive.
- --decrypt:
-
Decrypt the zip, pipe to a file.
Homework
- create a gpg key pair
- encrypt a test file
- decrypt a test file
- export public and private key pair
- delete public and private key pair
- re-import public and private key pair
- try to decrypt test file again
Misc
- The keyring files are binary and exist in ~/.gnupg.
Remarkbox
Comments