% Options for packages loaded elsewhere
\PassOptionsToPackage{unicode}{hyperref}
\PassOptionsToPackage{hyphens}{url}
%
\documentclass[
]{article}
\usepackage{amsmath,amssymb}
\usepackage{iftex}
\ifPDFTeX
  \usepackage[T1]{fontenc}
  \usepackage[utf8]{inputenc}
  \usepackage{textcomp} % provide euro and other symbols
\else % if luatex or xetex
  \usepackage{unicode-math} % this also loads fontspec
  \defaultfontfeatures{Scale=MatchLowercase}
  \defaultfontfeatures[\rmfamily]{Ligatures=TeX,Scale=1}
\fi
\usepackage{lmodern}
\ifPDFTeX\else
  % xetex/luatex font selection
\fi
% Use upquote if available, for straight quotes in verbatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
\IfFileExists{microtype.sty}{% use microtype if available
  \usepackage[]{microtype}
  \UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
}{}
\makeatletter
\@ifundefined{KOMAClassName}{% if non-KOMA class
  \IfFileExists{parskip.sty}{%
    \usepackage{parskip}
  }{% else
    \setlength{\parindent}{0pt}
    \setlength{\parskip}{6pt plus 2pt minus 1pt}}
}{% if KOMA class
  \KOMAoptions{parskip=half}}
\makeatother
\usepackage{xcolor}
\setlength{\emergencystretch}{3em} % prevent overfull lines
\providecommand{\tightlist}{%
  \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
\setcounter{secnumdepth}{-\maxdimen} % remove section numbering
\ifLuaTeX
  \usepackage{selnolig}  % disable illegal ligatures
\fi
\IfFileExists{bookmark.sty}{\usepackage{bookmark}}{\usepackage{hyperref}}
\IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if available
\urlstyle{same}
\hypersetup{
  pdftitle={linux-gpg},
  hidelinks,
  pdfcreator={LaTeX via pandoc}}

\title{linux-gpg}
\author{}
\date{}

\begin{document}
\maketitle

\hypertarget{linux-gpg}{%
\section{linux-gpg}\label{linux-gpg}}

Linux GPG \#\#\#\#\#\#\#\#\#\#\#

This document shows how to use the command line to work with PGP (GPG)
for encryption.

.. contents::

\hypertarget{create-a-key-pair}{%
\section{Create a key pair}\label{create-a-key-pair}}

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'.

\hypertarget{list-all-keys}{%
\section{List all keys}\label{list-all-keys}}

This is a great way to determine a `KeyID'

.. code-block:: bash

gpg --list-keys

\hypertarget{encrypt-a-test-message}{%
\section{Encrypt a test message}\label{encrypt-a-test-message}}

This process may also be used to Validate a private key passphrase.

.. code-block:: bash

gpg --local-user -as

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 -as

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

\hypertarget{decrypt-a-test-message}{%
\section{Decrypt a test message}\label{decrypt-a-test-message}}

.. 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.

\hypertarget{export-a-public-key}{%
\section{Export a public key}\label{export-a-public-key}}

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.

\hypertarget{export-a-private-key}{%
\section{Export a private key}\label{export-a-private-key}}

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.

\hypertarget{import-a-public-key}{%
\section{Import a public key}\label{import-a-public-key}}

.. 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.

\hypertarget{import-a-private-key}{%
\section{Import a private key}\label{import-a-private-key}}

.. 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.

\hypertarget{delete-a-public-key}{%
\section{Delete a public key}\label{delete-a-public-key}}

.. code-block:: bash

gpg --delete-key

\hypertarget{delete-a-private-key}{%
\section{Delete a private key}\label{delete-a-private-key}}

.. code-block:: bash

gpg --delete-secret-key

\hypertarget{edit-and-trust-a-key}{%
\section{Edit and Trust a key}\label{edit-and-trust-a-key}}

To edit a keys trust level (for instance to completely trust your own
key) do the following:

.. code-block:: bash

gpg --edit-key trust 5 y quit

\hypertarget{encrypt-a-directory}{%
\section{Encrypt a directory}\label{encrypt-a-directory}}

If you want to encrypt a directory instead of a file, use the gpg-zip
tool:

.. code-block:: bash

gpg-zip \textasciitilde/home/user/secret-files \textgreater{}
\textasciitilde/home/user/secret-files.gpg-zip

\hypertarget{symmetric-keys}{%
\section{Symmetric Keys}\label{symmetric-keys}}

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 \textasciitilde/.password-store \textgreater{}
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 \textasciitilde/.password-store \textgreater{}
password-store.gpg-zip

\hypertarget{homework}{%
\section{Homework}\label{homework}}

\begin{enumerate}
\tightlist
\item
  create a gpg key pair
\item
  encrypt a test file
\item
  decrypt a test file
\item
  export public and private key pair
\item
  delete public and private key pair
\item
  re-import public and private key pair
\item
  try to decrypt test file again
\end{enumerate}

\hypertarget{misc}{%
\section{Misc}\label{misc}}

\begin{itemize}
\tightlist
\item
  The keyring files are binary and exist in
  \emph{\textasciitilde/.gnupg}.
\end{itemize}

\end{document}
