WebsiteTemplate/cheatsheets/gpg-agent.html
2026-01-25 11:33:37 -04:00

145 lines
5.8 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self'; style-src 'self'; font-src 'self' data:; img-src 'self' data:; connect-src 'self'; base-uri 'self'; form-action 'self' https://defcon.social https://bsky.app;">
<meta http-equiv="X-Content-Type-Options" content="nosniff">
<link rel="stylesheet" href="../assets/css/style.css">
<link rel="icon" type="image/x-icon" href="../favicon.ico">
<script>
// Apply theme immediately to prevent flash
(function() {
const theme = localStorage.getItem('theme') ||
(window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light');
document.documentElement.setAttribute('data-theme', theme);
})();
</script>
<title>gpg-agent Cheatsheet - Launch Pad</title>
</head>
<body>
<button class="theme-toggle" id="themeToggle" aria-label="Toggle dark mode">
<svg class="theme-icon theme-icon-moon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"></path></svg>
<svg class="theme-icon theme-icon-sun" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="display: none;"><circle cx="12" cy="12" r="5"></circle><line x1="12" y1="1" x2="12" y2="3"></line><line x1="12" y1="21" x2="12" y2="23"></line><line x1="4.22" y1="4.22" x2="5.64" y2="5.64"></line><line x1="18.36" y1="18.36" x2="19.78" y2="19.78"></line><line x1="1" y1="12" x2="3" y2="12"></line><line x1="21" y1="12" x2="23" y2="12"></line><line x1="4.22" y1="19.78" x2="5.64" y2="18.36"></line><line x1="18.36" y1="5.64" x2="19.78" y2="4.22"></line></svg>
</button>
<br/><br/>
<div class="name">
__ _______________________ _________._________________________
\_ _____/ \______ \ / _ \ / _____/ / _____/ | | \_ _____/
| __) | _/ / /_\ \ / \ ___ / \ ___ | | | __)_
| \ | | \ / | \ \ \_\ \ \ \_\ \ | |___ | \
\___ / |____|_ / \____|__ / \______ / \______ / |_______ \ /_______ /
\/ \/ \/ \/ \/ \/ \/
</div>
<div class="blog-page-header">
<div class="blog-header-content">
<a href="/cheatsheets" class="back-link" title="Back to Cheatsheets">
<svg xmlns="http://www.w3.org/2000/svg" width="42" height="42" viewBox="0 0 24 24" class="home-icon"><path fill="currentColor" d="M10 20v-6h4v6h5v-8h3L12 3 2 12h3v8z"/></svg>
</a>
<h1 class="blog-page-title">gpg-agent Cheatsheet</h1>
</div>
</div>
<div class="blog-post-container">
<div class="blog-posts-container" style="max-width: 900px; margin: 0 auto;">
<div class="blog-post">
<div class="blog-post-content">
<p><a href="index.html">← Back to cheatsheets</a></p>
<p><a href="../index.html">← Home</a></p>
<hr>
<p>gpg-agent is a daemon that manages GPG private keys and passphrases. It caches passphrases so you don't have to enter them repeatedly, and can use hardware tokens or pinentry programs for secure passphrase entry.</p>
<hr>
<h2>Basic Usage</h2>
<ul>
<li>gpg-agent --daemon - Start the agent daemon</li>
</ul>
<ul>
<li>gpg-agent --kill - Stop the agent</li>
</ul>
<ul>
<li>gpg-agent --version - Show version</li>
</ul>
<hr>
<h2>Configuration</h2>
<ul>
<li>~/.gnupg/gpg-agent.conf - Main configuration file</li>
</ul>
<ul>
<li>default-cache-ttl 600 - Cache passphrase for 10 minutes</li>
</ul>
<ul>
<li>max-cache-ttl 7200 - Maximum cache time (2 hours)</li>
</ul>
<ul>
<li>pinentry-program /usr/bin/pinentry - Specify pinentry program</li>
</ul>
<ul>
<li>enable-ssh-support - Enable SSH agent emulation</li>
</ul>
<hr>
<h2>SSH Agent Emulation</h2>
<ul>
<li>enable-ssh-support in gpg-agent.conf - Enable SSH support</li>
</ul>
<ul>
<li>ssh-add -l - List SSH keys (when using gpg-agent)</li>
</ul>
<ul>
<li>export SSH_AUTH_SOCK=$(gpgconf --list-dirs agent-ssh-socket) - Set SSH socket</li>
</ul>
<ul>
<li>Add to ~/.bashrc or ~/.zshrc for persistent SSH support</li>
</ul>
<hr>
<h2>Reload Configuration</h2>
<ul>
<li>gpgconf --kill gpg-agent - Kill agent</li>
</ul>
<ul>
<li>gpgconf --launch gpg-agent - Restart agent</li>
</ul>
<ul>
<li>gpg-connect-agent reloadagent /bye - Reload without restart</li>
</ul>
<hr>
<h2>Common Examples</h2>
<h3>Start Agent</h3>
<pre><code>eval $(gpg-agent --daemon)</code></pre>
<p>Start agent and set environment variables.</p>
<h3>Check Agent Status</h3>
<pre><code>gpg-connect-agent /bye</code></pre>
<p>Test if agent is running.</p>
<h3>Clear Passphrase Cache</h3>
<pre><code>gpg-connect-agent reloadagent /bye</code></pre>
<p>Clear cached passphrases.</p>
<h3>SSH Support Setup</h3>
<pre><code>echo "enable-ssh-support" >> ~/.gnupg/gpg-agent.conf
gpgconf --kill gpg-agent
eval $(gpg-agent --daemon)</code></pre>
<p>Enable SSH agent emulation.</p>
<hr>
<h2>Tips</h2>
<ul>
<li>gpg-agent usually starts automatically when needed</li>
</ul>
<ul>
<li>Use pinentry for secure passphrase entry (GUI or TTY)</li>
</ul>
<ul>
<li>Set reasonable cache TTLs for security vs convenience</li>
</ul>
<ul>
<li>SSH agent emulation lets you use GPG keys for SSH</li>
</ul>
<ul>
<li>gpgconf is the modern way to manage gpg-agent</li>
</ul>
</div>
</div>
</div>
</div>
<script async type="text/javascript" src="../blog/analytics.js"></script>
<script src="../theme.js"></script>
</body>
</html>