Linux GPG ###########
This document shows how to use the command line to work with PGP (GPG) for encryption.
.. contents::
Use the following shell command:
.. code-block:: bash
gpg –gen-key
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’.
This is a great way to determine a ‘KeyID’
.. code-block:: bash
gpg –list-keys
This process may also be used to Validate a private key passphrase.
.. code-block:: bash
gpg –local-user
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:
.. code-block:: bash
gpg –local-user
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:
.. code-block:: bash
gpg –local-user MYKEYID1 -as secret-raw-payload.txt
.. code-block:: bash
gpg -d
Then paste the encrypted message into the terminal.
Optionally omit the ‘encrypted message file’ and paste the payload directly into the cmd prompt.
To export a public key for transportation or sharing, run this:
.. code-block:: bash
gpg –export -a
This will output the public key for a given KeyID as ascii, which may be shared and distributed to anyone.
To export a private key for transportation or backup, run this:
.. code-block:: bash
gpg –export-secret-key -a
This will output the private key for a given KeyID as ascii, which must be safely gaurded.
.. code-block:: bash
gpg –import
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.
.. code-block:: bash
gpg –allow-secret-key-import –import
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.
.. code-block:: bash
gpg –delete-key
.. code-block:: bash
gpg –delete-secret-key
To edit a keys trust level (for instance to completely trust your own key) do the following:
.. code-block:: bash
gpg –edit-key
If you want to encrypt a directory instead of a file, use the gpg-zip tool:
.. code-block:: bash
gpg-zip ~/home/user/secret-files > ~/home/user/secret-files.gpg-zip
If you want to use a single shared key use the –symmetric flag. It will prompt you for a password twice:
.. code-block:: bash
gpg-zip –symmetric ~/.password-store > password-store.gpg-zip
–list-archive: List the contents of the specified archive.
–decrypt: Decrypt the zip, pipe to a file.
.. code-block:: bash
gpg-zip –decrypt ~/.password-store > password-store.gpg-zip