<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Security on Benjamin Italiaander</title><link>https://tlnd.org/topic/security/</link><description>Recent content in Security on Benjamin Italiaander</description><generator>Hugo</generator><language>en</language><lastBuildDate>Sun, 29 Nov 2026 00:00:00 +0000</lastBuildDate><atom:link href="https://tlnd.org/topic/security/index.xml" rel="self" type="application/rss+xml"/><item><title>Contact</title><link>https://tlnd.org/contact/</link><pubDate>Sun, 29 Nov 2026 00:00:00 +0000</pubDate><guid>https://tlnd.org/contact/</guid><description>&lt;h1 id="-contact"&gt;📬 Contact&lt;/h1&gt;
&lt;p&gt;You can reach me through:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;💼 &lt;strong&gt;&lt;a href="https://www.linkedin.com/in/italiaander" class="external-link" target="_blank" rel="noopener"&gt;LinkedIn&lt;/a&gt;&lt;/strong&gt;: send me a message&lt;/li&gt;
&lt;li&gt;🐙 &lt;strong&gt;&lt;a href="https://github.com/Benjamin-Italiaander" class="external-link" target="_blank" rel="noopener"&gt;GitHub&lt;/a&gt;&lt;/strong&gt; and 🦊 &lt;strong&gt;&lt;a href="https://gitlab.com/italiaander" class="external-link" target="_blank" rel="noopener"&gt;GitLab&lt;/a&gt;&lt;/strong&gt;: for anything about my code and notes, open an issue&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="-something-confidential"&gt;🔐 Something confidential?&lt;/h2&gt;
&lt;p&gt;Send me a message on LinkedIn first. I&amp;rsquo;ll send you my public OpenPGP key and its fingerprint, and we check the fingerprint together through a second channel (in person, by phone or on a video call). Then only I can read what you send.&lt;/p&gt;</description></item><item><title>Public-key cryptography — from the mathematics to SSH, PGP and HTTPS</title><link>https://tlnd.org/math/public_key_cryptography/</link><pubDate>Sun, 29 Nov 2026 00:00:00 +0000</pubDate><guid>https://tlnd.org/math/public_key_cryptography/</guid><description>&lt;h1 id="-public-key-cryptography-from-the-mathematics-to-ssh-pgp-and-https"&gt;🔑 Public-key cryptography: from the mathematics to SSH, PGP and HTTPS&lt;/h1&gt;
&lt;p&gt;How can two computers that have never met agree on a secret while everybody is listening? How does a server prove that it is really the server? And what does your SSH key actually &lt;em&gt;do&lt;/em&gt; when you log in?&lt;/p&gt;
&lt;p&gt;Most explanations online give you either the formulas without the protocols, or the commands without the mathematics. This series connects the two. Part 1 builds the mathematics with &lt;strong&gt;small numbers you can check by hand&lt;/strong&gt;. The other parts follow real connections, with real output, and point at the exact formula from part 1 that is doing the work.&lt;/p&gt;</description></item><item><title>Public-key cryptography 1 — The mathematics</title><link>https://tlnd.org/math/public_key_cryptography/01_the_math/</link><pubDate>Sun, 29 Nov 2026 00:00:00 +0000</pubDate><guid>https://tlnd.org/math/public_key_cryptography/01_the_math/</guid><description>&lt;h1 id="-1-the-mathematics-of-public-key-cryptography"&gt;🔢 1. The mathematics of public-key cryptography&lt;/h1&gt;
&lt;p&gt;&lt;a href="https://tlnd.org/math/public_key_cryptography/"&gt;Overview&lt;/a&gt; · Next: &lt;a href="https://tlnd.org/math/public_key_cryptography/02_ssh/"&gt;2. SSH →&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Two computers that have never met, talking over a line that everybody can listen to, agree on a secret that nobody else knows. That sounds impossible, and for most of history it was. Since the 1970s it is done billions of times a day: every SSH login, every HTTPS page, every signed software update.&lt;/p&gt;
&lt;p&gt;This part explains the mathematics behind it. Every example uses &lt;strong&gt;small numbers that you can check by hand&lt;/strong&gt; (or in Python: &lt;code&gt;pow(base, exponent, modulus)&lt;/code&gt;). Real systems use the same formulas with numbers of 77 to 925 digits (&lt;a href="https://tlnd.org/math/public_key_cryptography/01h_why_so_many_digits/"&gt;why exactly those sizes?&lt;/a&gt;).&lt;/p&gt;</description></item><item><title>Public-key cryptography 2 — How an SSH connection is built</title><link>https://tlnd.org/math/public_key_cryptography/02_ssh/</link><pubDate>Sun, 29 Nov 2026 00:00:00 +0000</pubDate><guid>https://tlnd.org/math/public_key_cryptography/02_ssh/</guid><description>&lt;h1 id="-2-how-an-ssh-connection-is-built"&gt;🔐 2. How an SSH connection is built&lt;/h1&gt;
&lt;p&gt;&lt;a href="https://tlnd.org/math/public_key_cryptography/01_the_math/"&gt;← 1. The mathematics&lt;/a&gt; · &lt;a href="https://tlnd.org/math/public_key_cryptography/"&gt;Overview&lt;/a&gt; · Next: &lt;a href="https://tlnd.org/math/public_key_cryptography/03_pgp/"&gt;3. OpenPGP →&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;In &lt;a href="https://tlnd.org/math/public_key_cryptography/01_the_math/"&gt;part 1&lt;/a&gt; we saw the building blocks: Diffie–Hellman on elliptic curves, signatures, and the hybrid with ML-KEM. Here we follow one real connection, &lt;code&gt;ssh git@github.com&lt;/code&gt;, from the first byte to the moment you are logged in. Every log line on this page is real output of &lt;code&gt;ssh -vv&lt;/code&gt; (OpenSSH 10.2, November 2026), shortened.&lt;/p&gt;</description></item><item><title>Public-key cryptography 3 — How OpenPGP (GnuPG) encrypts and signs</title><link>https://tlnd.org/math/public_key_cryptography/03_pgp/</link><pubDate>Sun, 29 Nov 2026 00:00:00 +0000</pubDate><guid>https://tlnd.org/math/public_key_cryptography/03_pgp/</guid><description>&lt;h1 id="-3-how-openpgp-encrypts-and-signs"&gt;✉️ 3. How OpenPGP encrypts and signs&lt;/h1&gt;
&lt;p&gt;&lt;a href="https://tlnd.org/math/public_key_cryptography/02_ssh/"&gt;← 2. SSH&lt;/a&gt; · &lt;a href="https://tlnd.org/math/public_key_cryptography/"&gt;Overview&lt;/a&gt; · Next: &lt;a href="https://tlnd.org/math/public_key_cryptography/04_tls_wireguard_fido2_signal/"&gt;4. TLS, WireGuard, FIDO2 and Signal →&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://tlnd.org/math/public_key_cryptography/02_ssh/"&gt;SSH&lt;/a&gt; has a live connection: both sides are online and can do a Diffie–Hellman exchange back and forth. &lt;strong&gt;Email and files do not.&lt;/strong&gt; When you encrypt a file for Bob, Bob may be asleep, and he may read it in five years. There is no &amp;ldquo;back and forth&amp;rdquo;; you have one shot.&lt;/p&gt;</description></item><item><title>Public-key cryptography 4 — TLS, WireGuard, FIDO2 and Signal</title><link>https://tlnd.org/math/public_key_cryptography/04_tls_wireguard_fido2_signal/</link><pubDate>Sun, 29 Nov 2026 00:00:00 +0000</pubDate><guid>https://tlnd.org/math/public_key_cryptography/04_tls_wireguard_fido2_signal/</guid><description>&lt;h1 id="-4-tls-wireguard-fido2-and-signal"&gt;🌐 4. TLS, WireGuard, FIDO2 and Signal&lt;/h1&gt;
&lt;p&gt;&lt;a href="https://tlnd.org/math/public_key_cryptography/03_pgp/"&gt;← 3. OpenPGP&lt;/a&gt; · &lt;a href="https://tlnd.org/math/public_key_cryptography/"&gt;Overview&lt;/a&gt; · Next: &lt;a href="https://tlnd.org/math/public_key_cryptography/05_smime/"&gt;5. S/MIME →&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://tlnd.org/math/public_key_cryptography/02_ssh/"&gt;SSH&lt;/a&gt; and &lt;a href="https://tlnd.org/math/public_key_cryptography/03_pgp/"&gt;OpenPGP&lt;/a&gt; use the same building blocks from &lt;a href="https://tlnd.org/math/public_key_cryptography/01_the_math/"&gt;part 1&lt;/a&gt;, but combine them differently, because they solve different problems. Four more protocols you use every day make the differences even clearer. For each: what problem it solves, and which choice in the design follows from that.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id="1-tls-13-https"&gt;1. TLS 1.3: HTTPS&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;The problem:&lt;/strong&gt; your browser talks to millions of servers it has never seen before. &amp;ldquo;Trust on first use&amp;rdquo; like SSH (&lt;a href="https://tlnd.org/math/public_key_cryptography/02_ssh/#-do-i-know-this-server-known_hosts"&gt;part 2, ⑤&lt;/a&gt;) does not work: you would have to check a fingerprint for every website.&lt;/p&gt;</description></item><item><title>Public-key cryptography 5 — S/MIME: email encryption with certificates</title><link>https://tlnd.org/math/public_key_cryptography/05_smime/</link><pubDate>Sun, 29 Nov 2026 00:00:00 +0000</pubDate><guid>https://tlnd.org/math/public_key_cryptography/05_smime/</guid><description>&lt;h1 id="-5-smime-email-encryption-with-certificates"&gt;✉️ 5. S/MIME: email encryption with certificates&lt;/h1&gt;
&lt;p&gt;&lt;a href="https://tlnd.org/math/public_key_cryptography/04_tls_wireguard_fido2_signal/"&gt;← 4. TLS, WireGuard, FIDO2 and Signal&lt;/a&gt; · &lt;a href="https://tlnd.org/math/public_key_cryptography/"&gt;Overview&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;There are two standards for signing and encrypting email: &lt;strong&gt;OpenPGP&lt;/strong&gt; (&lt;a href="https://tlnd.org/math/public_key_cryptography/03_pgp/"&gt;part 3&lt;/a&gt;) and &lt;strong&gt;S/MIME&lt;/strong&gt;. They use the same mathematics. The big difference is the answer to the question every protocol has to answer: &lt;em&gt;whose key is this?&lt;/em&gt; OpenPGP lets people vouch for each other (or you check a fingerprint yourself); S/MIME uses &lt;strong&gt;certificates from a certificate authority&lt;/strong&gt;, exactly like HTTPS (&lt;a href="https://tlnd.org/math/public_key_cryptography/04_tls_wireguard_fido2_signal/"&gt;part 4&lt;/a&gt;). That makes S/MIME the choice of companies, governments and universities: it is built into Outlook, Apple Mail, Thunderbird and most phones, and an organisation can hand out certificates centrally.&lt;/p&gt;</description></item><item><title>Harden an SSH Server: sshd, Firewall and fail2ban</title><link>https://tlnd.org/Linux/ssh/ssh_server_hardening/</link><pubDate>Sat, 28 Nov 2026 00:00:00 +0000</pubDate><guid>https://tlnd.org/Linux/ssh/ssh_server_hardening/</guid><description>&lt;h1 id="-harden-an-ssh-server"&gt;🛡️ Harden an SSH server&lt;/h1&gt;
&lt;p&gt;Every server with port 22 open to the internet gets thousands of login attempts a day. These four steps make them harmless.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;⚠️ &lt;strong&gt;Keep your current SSH session open&lt;/strong&gt; while you change these settings, and test with a &lt;strong&gt;second&lt;/strong&gt; session. If something is wrong, you can still fix it.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;hr&gt;
&lt;h2 id="1-log-in-with-a-key-first"&gt;1. Log in with a key first&lt;/h2&gt;
&lt;p&gt;Make sure you can log in with an SSH key before you turn passwords off:&lt;/p&gt;</description></item><item><title>How a TOTP Code Is Calculated</title><link>https://tlnd.org/math/totp_explained/</link><pubDate>Sat, 28 Nov 2026 00:00:00 +0000</pubDate><guid>https://tlnd.org/math/totp_explained/</guid><description>&lt;h1 id="-how-a-totp-code-is-calculated"&gt;🔢 How a TOTP code is calculated&lt;/h1&gt;
&lt;p&gt;The six digits in your authenticator app (or on your &lt;a href="https://tlnd.org/Linux/yubikey/03_totp_oath/"&gt;YubiKey&lt;/a&gt;, or from &lt;a href="https://tlnd.org/Linux/bash_otp_generator/"&gt;oathtool in the terminal&lt;/a&gt;) are not random. They are calculated from two things: a &lt;strong&gt;shared secret&lt;/strong&gt; and &lt;strong&gt;the current time&lt;/strong&gt;. Your phone and the server both do the same calculation, so they get the same code without ever talking to each other.&lt;/p&gt;
&lt;p&gt;The recipe is open: &lt;strong&gt;HOTP&lt;/strong&gt; (&lt;a href="https://www.rfc-editor.org/rfc/rfc4226" class="external-link" target="_blank" rel="noopener"&gt;RFC 4226&lt;/a&gt;) and &lt;strong&gt;TOTP&lt;/strong&gt; (&lt;a href="https://www.rfc-editor.org/rfc/rfc6238" class="external-link" target="_blank" rel="noopener"&gt;RFC 6238&lt;/a&gt;).&lt;/p&gt;</description></item><item><title>YubiKey 9 — Disk encryption (LUKS) and Git signing</title><link>https://tlnd.org/Linux/yubikey/09_luks_and_git_signing/</link><pubDate>Sat, 28 Nov 2026 00:00:00 +0000</pubDate><guid>https://tlnd.org/Linux/yubikey/09_luks_and_git_signing/</guid><description>&lt;h1 id="9-disk-encryption-luks-and-git-signing"&gt;9. Disk encryption (LUKS) and Git signing&lt;/h1&gt;
&lt;p&gt;Two more things your YubiKey can do with &lt;strong&gt;FIDO2&lt;/strong&gt;, the same function you used for &lt;a href="https://tlnd.org/Linux/yubikey/04_ssh_fido2/"&gt;SSH in chapter 4&lt;/a&gt;:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Unlock your encrypted disk&lt;/strong&gt; at boot: insert the key, type the FIDO2 PIN, touch. No long passphrase any more.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Sign your Git commits&lt;/strong&gt;, so everyone (and GitHub) can see that a commit really came from you.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Before you start: you need a FIDO2 PIN (&lt;a href="https://tlnd.org/Linux/yubikey/02_first_time_setup/"&gt;chapter 2&lt;/a&gt;), and ideally a &lt;strong&gt;second YubiKey&lt;/strong&gt; as a backup.&lt;/p&gt;</description></item><item><title>YubiKey 1 — Installation (Debian/Ubuntu and Fedora)</title><link>https://tlnd.org/Linux/yubikey/01_installation/</link><pubDate>Wed, 01 Oct 2025 12:30:21 +0100</pubDate><guid>https://tlnd.org/Linux/yubikey/01_installation/</guid><description>&lt;h1 id="1-installation"&gt;1. Installation&lt;/h1&gt;
&lt;p&gt;&lt;a href="https://tlnd.org/Linux/yubikey/"&gt;← Back to overview&lt;/a&gt; · Next: &lt;a href="https://tlnd.org/Linux/yubikey/02_first_time_setup/"&gt;2. First-time setup →&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Goal:&lt;/strong&gt; install the software, start the smartcard daemon and see your YubiKey with &lt;code&gt;ykman info&lt;/code&gt; and &lt;code&gt;gpg --card-status&lt;/code&gt;.&lt;/p&gt;
&lt;table&gt;
 &lt;thead&gt;
 &lt;tr&gt;
 &lt;th&gt;Package&lt;/th&gt;
 &lt;th&gt;What it is&lt;/th&gt;
 &lt;/tr&gt;
 &lt;/thead&gt;
 &lt;tbody&gt;
 &lt;tr&gt;
 &lt;td&gt;GnuPG (&lt;code&gt;gnupg2&lt;/code&gt;)&lt;/td&gt;
 &lt;td&gt;The universal crypto engine (OpenPGP)&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;scdaemon&lt;/td&gt;
 &lt;td&gt;Smartcard daemon for GnuPG&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;pcsc-lite / pcscd&lt;/td&gt;
 &lt;td&gt;PC/SC smartcard daemon (talks to the YubiKey)&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;yubikey-manager&lt;/td&gt;
 &lt;td&gt;&lt;code&gt;ykman&lt;/code&gt;, the YubiKey CLI&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;pcsc-tools&lt;/td&gt;
 &lt;td&gt;&lt;code&gt;pcsc_scan&lt;/code&gt;, handy for debugging&lt;/td&gt;
 &lt;/tr&gt;
 &lt;/tbody&gt;
&lt;/table&gt;
&lt;hr&gt;
&lt;h2 id="11-debian--ubuntu"&gt;1.1 Debian / Ubuntu&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;sudo apt update
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;sudo apt install gnupg2 scdaemon pcscd pcsc-tools yubikey-manager yubikey-personalization pipx
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;sudo systemctl &lt;span class="nb"&gt;enable&lt;/span&gt; --now pcscd.socket
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Optional (Ubuntu only) — newer Yubico packages from the official PPA:&lt;/p&gt;</description></item><item><title>YubiKey 2 — First-time setup (the bare minimum)</title><link>https://tlnd.org/Linux/yubikey/02_first_time_setup/</link><pubDate>Wed, 01 Oct 2025 12:30:21 +0100</pubDate><guid>https://tlnd.org/Linux/yubikey/02_first_time_setup/</guid><description>&lt;h1 id="2-first-time-setup--the-bare-minimum"&gt;2. First-Time Setup — The Bare Minimum&lt;/h1&gt;
&lt;p&gt;&lt;a href="https://tlnd.org/Linux/yubikey/01_installation/"&gt;← 1. Installation&lt;/a&gt; · &lt;a href="https://tlnd.org/Linux/yubikey/"&gt;Overview&lt;/a&gt; · Next: &lt;a href="https://tlnd.org/Linux/yubikey/03_totp_oath/"&gt;3. TOTP codes →&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Every YubiKey leaves the factory with &lt;strong&gt;the same, publicly known defaults&lt;/strong&gt;. Until you change them, anybody who holds your key can use it.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;✅ Do this checklist for &lt;strong&gt;every&lt;/strong&gt; YubiKey you own, including the backup key.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;table&gt;
 &lt;thead&gt;
 &lt;tr&gt;
 &lt;th&gt;✔&lt;/th&gt;
 &lt;th&gt;Application&lt;/th&gt;
 &lt;th&gt;What to change&lt;/th&gt;
 &lt;th&gt;Default&lt;/th&gt;
 &lt;/tr&gt;
 &lt;/thead&gt;
 &lt;tbody&gt;
 &lt;tr&gt;
 &lt;td&gt;☐&lt;/td&gt;
 &lt;td&gt;FIDO2&lt;/td&gt;
 &lt;td&gt;Set a PIN&lt;/td&gt;
 &lt;td&gt;&lt;em&gt;(none)&lt;/em&gt;&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;☐&lt;/td&gt;
 &lt;td&gt;PIV&lt;/td&gt;
 &lt;td&gt;PIN&lt;/td&gt;
 &lt;td&gt;&lt;code&gt;123456&lt;/code&gt;&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;☐&lt;/td&gt;
 &lt;td&gt;PIV&lt;/td&gt;
 &lt;td&gt;PUK&lt;/td&gt;
 &lt;td&gt;&lt;code&gt;12345678&lt;/code&gt;&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;☐&lt;/td&gt;
 &lt;td&gt;PIV&lt;/td&gt;
 &lt;td&gt;Management key&lt;/td&gt;
 &lt;td&gt;&lt;code&gt;010203040506070801020304050607080102030405060708&lt;/code&gt;&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;☐&lt;/td&gt;
 &lt;td&gt;OpenPGP&lt;/td&gt;
 &lt;td&gt;User PIN&lt;/td&gt;
 &lt;td&gt;&lt;code&gt;123456&lt;/code&gt;&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;☐&lt;/td&gt;
 &lt;td&gt;OpenPGP&lt;/td&gt;
 &lt;td&gt;Admin PIN&lt;/td&gt;
 &lt;td&gt;&lt;code&gt;12345678&lt;/code&gt;&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;☐&lt;/td&gt;
 &lt;td&gt;OATH&lt;/td&gt;
 &lt;td&gt;Password&lt;/td&gt;
 &lt;td&gt;&lt;em&gt;(none)&lt;/em&gt; — see &lt;a href="https://tlnd.org/Linux/yubikey/03_totp_oath/"&gt;chapter 3&lt;/a&gt;&lt;/td&gt;
 &lt;/tr&gt;
 &lt;/tbody&gt;
&lt;/table&gt;
&lt;blockquote&gt;
&lt;p&gt;💾 &lt;strong&gt;Write down your PUK, Admin PIN and management key and store them offline&lt;/strong&gt; (paper, or a QR code in a safe).
I have an instruction for making a QR code in the CLI &lt;a href="https://github.com/Benjamin-Italiaander/My_Notes/blob/main/Linux/cli/qrcode.md" class="external-link" target="_blank" rel="noopener"&gt;here&lt;/a&gt;.&lt;/p&gt;</description></item><item><title>YubiKey 3 — TOTP codes (OATH)</title><link>https://tlnd.org/Linux/yubikey/03_totp_oath/</link><pubDate>Wed, 01 Oct 2025 12:30:21 +0100</pubDate><guid>https://tlnd.org/Linux/yubikey/03_totp_oath/</guid><description>&lt;h1 id="3-totp-codes-oath"&gt;3. TOTP Codes (OATH)&lt;/h1&gt;
&lt;p&gt;&lt;a href="https://tlnd.org/Linux/yubikey/02_first_time_setup/"&gt;← 2. First-time setup&lt;/a&gt; · &lt;a href="https://tlnd.org/Linux/yubikey/"&gt;Overview&lt;/a&gt; · Next: &lt;a href="https://tlnd.org/Linux/yubikey/04_ssh_fido2/"&gt;4. SSH with FIDO2 →&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Goal:&lt;/strong&gt; store your authenticator codes (GitHub, Google, …) on the YubiKey instead of (or next to) your phone.&lt;/p&gt;
&lt;h3 id="why-copy-an-existing-totp-secret"&gt;Why copy an existing TOTP secret?&lt;/h3&gt;
&lt;p&gt;When a website shows you a QR code, it also shows a text secret (Base32, e.g. &lt;code&gt;JBSWY3DPEHPK3PXP&lt;/code&gt;). If you add &lt;strong&gt;that same secret&lt;/strong&gt; to several YubiKeys (and/or an authenticator app), they all produce the same codes — so you have a backup.&lt;/p&gt;</description></item><item><title>YubiKey 4 — SSH with FIDO2</title><link>https://tlnd.org/Linux/yubikey/04_ssh_fido2/</link><pubDate>Wed, 01 Oct 2025 12:30:21 +0100</pubDate><guid>https://tlnd.org/Linux/yubikey/04_ssh_fido2/</guid><description>&lt;h1 id="4-ssh-with-fido2"&gt;4. SSH with FIDO2&lt;/h1&gt;
&lt;p&gt;&lt;a href="https://tlnd.org/Linux/yubikey/03_totp_oath/"&gt;← 3. TOTP codes&lt;/a&gt; · &lt;a href="https://tlnd.org/Linux/yubikey/"&gt;Overview&lt;/a&gt; · Next: &lt;a href="https://tlnd.org/Linux/yubikey/05_openpgp_gpg_ssh/"&gt;5. OpenPGP →&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Goal:&lt;/strong&gt; an SSH key whose private part never leaves the YubiKey. This is the &lt;strong&gt;simplest&lt;/strong&gt; secure way to use SSH with a YubiKey. (OpenPGP, chapter 5, is more flexible but more complex.)&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Before you start:&lt;/strong&gt; complete &lt;a href="https://tlnd.org/Linux/yubikey/02_first_time_setup/"&gt;chapter 2&lt;/a&gt; — at least the FIDO2 PIN. You should know the difference between a private and a public key.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id="41-how-it-works"&gt;4.1 How it works&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;The &lt;strong&gt;real private key&lt;/strong&gt; is created and stored &lt;strong&gt;inside the YubiKey&lt;/strong&gt; — it can never be extracted or imported.&lt;/li&gt;
&lt;li&gt;A small &lt;strong&gt;key handle&lt;/strong&gt; file is stored in &lt;code&gt;~/.ssh&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;To log in you need the &lt;strong&gt;YubiKey + touch (+ PIN)&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;table&gt;
 &lt;thead&gt;
 &lt;tr&gt;
 &lt;th&gt;Never share&lt;/th&gt;
 &lt;th&gt;Safe to share&lt;/th&gt;
 &lt;/tr&gt;
 &lt;/thead&gt;
 &lt;tbody&gt;
 &lt;tr&gt;
 &lt;td&gt;&lt;code&gt;~/.ssh/yubikey&lt;/code&gt; (key handle)&lt;/td&gt;
 &lt;td&gt;&lt;code&gt;~/.ssh/yubikey.pub&lt;/code&gt; (public key)&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;your YubiKey&lt;/td&gt;
 &lt;td&gt;&lt;/td&gt;
 &lt;/tr&gt;
 &lt;/tbody&gt;
&lt;/table&gt;
&lt;blockquote&gt;
&lt;p&gt;💡 Disable password logins on your servers (&lt;code&gt;PasswordAuthentication no&lt;/code&gt;) to get the full benefit.&lt;/p&gt;</description></item><item><title>YubiKey 5 — OpenPGP: GPG and SSH</title><link>https://tlnd.org/Linux/yubikey/05_openpgp_gpg_ssh/</link><pubDate>Wed, 01 Oct 2025 12:30:21 +0100</pubDate><guid>https://tlnd.org/Linux/yubikey/05_openpgp_gpg_ssh/</guid><description>&lt;h1 id="5-openpgp--gpg--ssh"&gt;5. OpenPGP — GPG + SSH&lt;/h1&gt;
&lt;p&gt;&lt;a href="https://tlnd.org/Linux/yubikey/04_ssh_fido2/"&gt;← 4. SSH with FIDO2&lt;/a&gt; · &lt;a href="https://tlnd.org/Linux/yubikey/"&gt;Overview&lt;/a&gt; · Next: &lt;a href="https://tlnd.org/Linux/yubikey/06_age_piv/"&gt;6. age encryption →&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Goal:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;a GPG &lt;strong&gt;master key&lt;/strong&gt; that is kept offline,&lt;/li&gt;
&lt;li&gt;three &lt;strong&gt;subkeys&lt;/strong&gt; (Sign, Encrypt, Authenticate) on the YubiKey,&lt;/li&gt;
&lt;li&gt;SSH logins through &lt;code&gt;gpg-agent&lt;/code&gt; with the Authentication subkey,&lt;/li&gt;
&lt;li&gt;multi-hop SSH with &lt;code&gt;ProxyJump&lt;/code&gt; (without agent forwarding).&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Before you start:&lt;/strong&gt; &lt;a href="https://tlnd.org/Linux/yubikey/01_installation/"&gt;chapter 1&lt;/a&gt; (incl. Fedora step 5 for the shell settings).&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id="51-the-idea-in-one-picture"&gt;5.1 The idea in one picture&lt;/h2&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;Master key [C] ──► offline backup (USB in a safe) — only for creating/renewing subkeys
 ├─ Subkey [S] Sign ──► YubiKey slot 1
 ├─ Subkey [E] Encrypt ──► YubiKey slot 2
 └─ Subkey [A] Authenticate ──► YubiKey slot 3 ──► used for SSH
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;In the commands below, replace &lt;code&gt;&amp;lt;KEYID&amp;gt;&lt;/code&gt; with your key ID or email address.&lt;/p&gt;</description></item><item><title>YubiKey 7 — Linux login with PAM (sudo, desktop, TTY)</title><link>https://tlnd.org/Linux/yubikey/07_linux_login_pam/</link><pubDate>Wed, 01 Oct 2025 12:30:21 +0100</pubDate><guid>https://tlnd.org/Linux/yubikey/07_linux_login_pam/</guid><description>&lt;h1 id="7-linux-login-with-pam-sudo-desktop-tty"&gt;7. Linux Login with PAM (sudo, desktop, TTY)&lt;/h1&gt;
&lt;p&gt;&lt;a href="https://tlnd.org/Linux/yubikey/06_age_piv/"&gt;← 6. age encryption&lt;/a&gt; · &lt;a href="https://tlnd.org/Linux/yubikey/"&gt;Overview&lt;/a&gt; · Next: &lt;a href="https://tlnd.org/Linux/yubikey/08_troubleshooting/"&gt;8. Troubleshooting →&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Goal:&lt;/strong&gt; require your YubiKey (touch) for &lt;code&gt;sudo&lt;/code&gt;, &lt;code&gt;su&lt;/code&gt;, the desktop login (GDM) and TTY login, using &lt;code&gt;pam_u2f&lt;/code&gt; (FIDO2/U2F).&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;🚨 &lt;strong&gt;You can lock yourself out.&lt;/strong&gt; Keep a &lt;strong&gt;root shell open in a second terminal&lt;/strong&gt; (&lt;code&gt;sudo -i&lt;/code&gt;) while you change PAM files, and test before you log out. If something breaks, remove the line you added.&lt;/p&gt;</description></item><item><title>YubiKey 8 — Troubleshooting</title><link>https://tlnd.org/Linux/yubikey/08_troubleshooting/</link><pubDate>Wed, 01 Oct 2025 12:30:21 +0100</pubDate><guid>https://tlnd.org/Linux/yubikey/08_troubleshooting/</guid><description>&lt;h1 id="8-troubleshooting"&gt;8. Troubleshooting&lt;/h1&gt;
&lt;p&gt;&lt;a href="https://tlnd.org/Linux/yubikey/07_linux_login_pam/"&gt;← 7. Linux login&lt;/a&gt; · &lt;a href="https://tlnd.org/Linux/yubikey/"&gt;Overview&lt;/a&gt;&lt;/p&gt;
&lt;h2 id="-quick-checks"&gt;🧪 Quick checks&lt;/h2&gt;
&lt;p&gt;Run these first — they tell you where the problem is:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;lsusb &lt;span class="p"&gt;|&lt;/span&gt; grep -i yubi &lt;span class="c1"&gt;# is the key on USB?&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;systemctl status pcscd.socket &lt;span class="c1"&gt;# is the smartcard daemon running?&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;ykman info &lt;span class="c1"&gt;# can ykman talk to it?&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;gpg --card-status &lt;span class="c1"&gt;# can GnuPG talk to it?&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;gpg -K &lt;span class="c1"&gt;# ssb&amp;gt; = subkey on the YubiKey&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$SSH_AUTH_SOCK&lt;/span&gt; &lt;span class="c1"&gt;# which SSH agent is used?&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;ssh-add -L &lt;span class="c1"&gt;# which keys does the agent offer?&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;ssh -vvv host &lt;span class="c1"&gt;# what happens during login?&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;hr&gt;
&lt;h2 id="the-yubikey-is-not-found"&gt;The YubiKey is not found&lt;/h2&gt;
&lt;h3 id="gpg---card-status--no-such-device--card-not-present"&gt;&lt;code&gt;gpg --card-status&lt;/code&gt; → &lt;em&gt;No such device&lt;/em&gt; / &lt;em&gt;Card not present&lt;/em&gt;&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;Is &lt;code&gt;pcscd&lt;/code&gt; running?
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;sudo systemctl &lt;span class="nb"&gt;enable&lt;/span&gt; --now pcscd.socket
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;Restart scdaemon:
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;gpgconf --kill scdaemon
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;gpg --card-status
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;Let scdaemon use &lt;code&gt;pcscd&lt;/code&gt; instead of its own USB driver — add to &lt;code&gt;~/.gnupg/scdaemon.conf&lt;/code&gt;:
&lt;pre tabindex="0"&gt;&lt;code class="language-conf" data-lang="conf"&gt;disable-ccid
&lt;/code&gt;&lt;/pre&gt;then &lt;code&gt;gpgconf --kill scdaemon&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Fedora:&lt;/strong&gt; &lt;em&gt;access denied&lt;/em&gt; from polkit → add the polkit rule from &lt;a href="https://tlnd.org/Linux/yubikey/01_installation/#step-4--polkit-rule-only-if-you-get-access-denied--no-such-device"&gt;1.2 step 4&lt;/a&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id="ykman-works-but-gpg-doesnt-or-the-other-way-around"&gt;&lt;code&gt;ykman&lt;/code&gt; works but &lt;code&gt;gpg&lt;/code&gt; doesn&amp;rsquo;t (or the other way around)&lt;/h3&gt;
&lt;p&gt;Only one program can hold the card at a time. Kill the other one:&lt;/p&gt;</description></item><item><title>YubiKey on Linux — Get Started the Safe Way</title><link>https://tlnd.org/Linux/yubikey/</link><pubDate>Mon, 01 Sep 2025 12:30:21 +0100</pubDate><guid>https://tlnd.org/Linux/yubikey/</guid><description>&lt;h1 id="-yubikey-on-linux--get-started-the-safe-way"&gt;🔐 YubiKey on Linux — Get Started the Safe Way&lt;/h1&gt;
&lt;p&gt;A practical guide to using a YubiKey from the Linux command line.
Commands are given for &lt;strong&gt;Debian/Ubuntu&lt;/strong&gt; (&lt;code&gt;apt&lt;/code&gt;) and &lt;strong&gt;Fedora&lt;/strong&gt; (&lt;code&gt;dnf&lt;/code&gt;).&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Hardware tokens can raise your security to a very high level — &lt;strong&gt;but only when they are configured and used correctly.&lt;/strong&gt;
A badly configured token gives you a &lt;em&gt;false sense of security&lt;/em&gt;, not actual protection.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;hr&gt;
&lt;h2 id="-chapters"&gt;📚 Chapters&lt;/h2&gt;
&lt;p&gt;Work through chapters 1 and 2 first. After that, pick the chapters for the functions you actually use.&lt;/p&gt;</description></item><item><title>Best practice: generate an SSH key pair</title><link>https://tlnd.org/Linux/ssh/ssh_keygen/</link><pubDate>Wed, 20 Apr 2022 00:00:00 +0000</pubDate><guid>https://tlnd.org/Linux/ssh/ssh_keygen/</guid><description>&lt;p&gt;&lt;img src="https://tlnd.org/Linux/ssh/ssh-150x150.png" alt="ssh 150x150" title="ssh-150x150.png" loading="lazy" decoding="async"&gt;&lt;/p&gt;
&lt;h3 id="introduction"&gt;Introduction&lt;/h3&gt;
&lt;p&gt;A short best-practice guide on how to generate an SSH key pair on the Linux command line.&lt;/p&gt;
&lt;p&gt;A public/private key pair is a pair of mathematically related keys used in asymmetric cryptography for authentication, digital signatures or key establishment. As the name indicates, the private key is used by the owner of the key pair, is kept secret and should be protected at all times, while the public key can be published and used by the other party to complete the protocol or to verify the operations performed with the private key.&lt;/p&gt;</description></item><item><title>Permissions for SSH Files</title><link>https://tlnd.org/Linux/ssh/chmod_ssh_files/</link><pubDate>Fri, 09 Dec 2016 00:00:00 +0000</pubDate><guid>https://tlnd.org/Linux/ssh/chmod_ssh_files/</guid><description>&lt;h1 id="permissions-for-ssh-files"&gt;Permissions for SSH files&lt;/h1&gt;
&lt;table&gt;
 &lt;thead&gt;
 &lt;tr&gt;
 &lt;th&gt;What&lt;/th&gt;
 &lt;th&gt;Path&lt;/th&gt;
 &lt;th&gt;chmod&lt;/th&gt;
 &lt;th&gt;Result&lt;/th&gt;
 &lt;/tr&gt;
 &lt;/thead&gt;
 &lt;tbody&gt;
 &lt;tr&gt;
 &lt;td&gt;SSH folder&lt;/td&gt;
 &lt;td&gt;&lt;code&gt;~/.ssh&lt;/code&gt;&lt;/td&gt;
 &lt;td&gt;700&lt;/td&gt;
 &lt;td&gt;&lt;code&gt;drwx------&lt;/code&gt;&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;Public key&lt;/td&gt;
 &lt;td&gt;&lt;code&gt;~/.ssh/id_ed25519.pub&lt;/code&gt;&lt;/td&gt;
 &lt;td&gt;644&lt;/td&gt;
 &lt;td&gt;&lt;code&gt;-rw-r--r--&lt;/code&gt;&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;Private key&lt;/td&gt;
 &lt;td&gt;&lt;code&gt;~/.ssh/id_ed25519&lt;/code&gt;&lt;/td&gt;
 &lt;td&gt;600&lt;/td&gt;
 &lt;td&gt;&lt;code&gt;-rw-------&lt;/code&gt;&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;Authorized keys&lt;/td&gt;
 &lt;td&gt;&lt;code&gt;~/.ssh/authorized_keys&lt;/code&gt;&lt;/td&gt;
 &lt;td&gt;600&lt;/td&gt;
 &lt;td&gt;&lt;code&gt;-rw-------&lt;/code&gt;&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;Config&lt;/td&gt;
 &lt;td&gt;&lt;code&gt;~/.ssh/config&lt;/code&gt;&lt;/td&gt;
 &lt;td&gt;600&lt;/td&gt;
 &lt;td&gt;&lt;code&gt;-rw-------&lt;/code&gt;&lt;/td&gt;
 &lt;/tr&gt;
 &lt;/tbody&gt;
&lt;/table&gt;
&lt;h2 id="home-folder"&gt;Home folder&lt;/h2&gt;
&lt;p&gt;Your home folder must not be writable by others, or SSH will refuse your keys. 755 (&lt;code&gt;drwxr-xr-x&lt;/code&gt;) is the most it may be:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;chmod g-w,o-w ~
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The same goes for every other key you have, such as &lt;code&gt;~/.ssh/id_rsa&lt;/code&gt; (older RSA keys) or &lt;code&gt;~/.ssh/yubikey&lt;/code&gt;: private keys 600, public keys 644. Set it all at once:&lt;/p&gt;</description></item><item><title>Key Derivation Function</title><link>https://tlnd.org/math/key_derivation_function/</link><pubDate>Fri, 28 Oct 2016 00:00:00 +0000</pubDate><guid>https://tlnd.org/math/key_derivation_function/</guid><description>&lt;h1 id="key-derivation-function-kdf"&gt;Key Derivation Function (KDF)&lt;/h1&gt;
&lt;h2 id="cryptographic-key-derivation"&gt;Cryptographic Key Derivation&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Cryptography | Key Management | Password Security&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;A &lt;strong&gt;Key Derivation Function (KDF)&lt;/strong&gt; is a cryptographic algorithm used to derive one or more secret keys from an existing secret value.&lt;/p&gt;
&lt;p&gt;This original value may be a master key, password, passphrase, or another form of secret key material.&lt;/p&gt;
&lt;p&gt;KDFs are fundamental components of modern cryptographic systems and are widely used for encryption, authentication, password protection, and secure key management.&lt;/p&gt;</description></item><item><title>Bash OTP Generator</title><link>https://tlnd.org/Linux/bash_otp_generator/</link><pubDate>Sun, 05 Jun 2016 00:00:00 +0000</pubDate><guid>https://tlnd.org/Linux/bash_otp_generator/</guid><description>&lt;h1 id="create-an-otp-mfa-tool-in-the-bash-terminal"&gt;Create an OTP MFA Tool in the Bash Terminal&lt;/h1&gt;
&lt;p&gt;I was tired of using &lt;strong&gt;Google Authenticator&lt;/strong&gt;, so I found a simple way to generate my own &lt;strong&gt;OTP (One-Time Password)&lt;/strong&gt; codes directly in &lt;strong&gt;Bash&lt;/strong&gt;.&lt;br&gt;
Just replace the example string below (&lt;code&gt;JHJH...&lt;/code&gt;) with your own secret key.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;/usr/bin/oathtool -b --totp &lt;span class="s1"&gt;&amp;#39;JHJHJHJHJHJHJHJHJHJHJHJHJ&amp;#39;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;If you want to copy the token directly to your clipboard, just use &lt;strong&gt;xclip&lt;/strong&gt;:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;/usr/bin/oathtool -b --totp &lt;span class="s1"&gt;&amp;#39;JHJHJHJHJHJHJHJHJHJHJHJHJ&amp;#39;&lt;/span&gt; &lt;span class="p"&gt;|&lt;/span&gt; xclip -selection c
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This way, you can easily run your own OTP generator right in the terminal.&lt;/p&gt;</description></item><item><title>Login Email Notifications with PAM</title><link>https://tlnd.org/Linux/ssh/login_notification/</link><pubDate>Fri, 06 May 2016 00:00:00 +0000</pubDate><guid>https://tlnd.org/Linux/ssh/login_notification/</guid><description>&lt;h1 id="linux-login-email-notifications-using-pam"&gt;Linux Login Email Notifications using PAM&lt;/h1&gt;
&lt;p&gt;This setup sends an email notification whenever someone logs into the Linux system over SSH or on a local console.&lt;/p&gt;
&lt;p&gt;Useful for:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Detecting unexpected access&lt;/li&gt;
&lt;li&gt;Monitoring servers remotely&lt;/li&gt;
&lt;li&gt;Security auditing&lt;/li&gt;
&lt;li&gt;Home lab notifications&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="install-the-required-mail-utility"&gt;Install the Required Mail Utility&lt;/h2&gt;
&lt;p&gt;Install a simple mail client:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;apt update
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;apt install bsd-mailx
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;hr&gt;
&lt;h2 id="create-the-login-notification-script"&gt;Create the Login Notification Script&lt;/h2&gt;
&lt;p&gt;Create the script:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;nano /usr/local/bin/login-notify.sh
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Contents:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="cp"&gt;#!/bin/bash
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;## DON&amp;#39;T FORGET TO CHANGE YOUR EMAIL ADDRESS!&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nv"&gt;TO&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;admin@example.com&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nv"&gt;HOST&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;&lt;/span&gt;&lt;span class="k"&gt;$(&lt;/span&gt;hostname -f 2&amp;gt;/dev/null &lt;span class="o"&gt;||&lt;/span&gt; hostname&lt;span class="k"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;&lt;/span&gt;&lt;span class="nv"&gt;$PAM_TYPE&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;&lt;/span&gt; in
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;auth&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nv"&gt;DESCRIPTION&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;Authentication attempt (password, SSH key, MFA or other authentication mechanism)&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;account&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nv"&gt;DESCRIPTION&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;Account validation (access rules, expiration checks, login restrictions)&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;open_session&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nv"&gt;DESCRIPTION&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;User session opened successfully (login)&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;close_session&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nv"&gt;DESCRIPTION&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;User session closed (logout or disconnect)&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;password&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nv"&gt;DESCRIPTION&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;Password change operation&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;*&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nv"&gt;DESCRIPTION&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;Unknown PAM event&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;esac&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nv"&gt;SUBJECT&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;PAM Event [&lt;/span&gt;&lt;span class="nv"&gt;$PAM_TYPE&lt;/span&gt;&lt;span class="s2"&gt;] on &lt;/span&gt;&lt;span class="nv"&gt;$HOST&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nv"&gt;MESSAGE&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="s2"&gt;PAM Event Notification
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="s2"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="s2"&gt;Event Type : &lt;/span&gt;&lt;span class="nv"&gt;$PAM_TYPE&lt;/span&gt;&lt;span class="s2"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="s2"&gt;Description: &lt;/span&gt;&lt;span class="nv"&gt;$DESCRIPTION&lt;/span&gt;&lt;span class="s2"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="s2"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="s2"&gt;Hostname : &lt;/span&gt;&lt;span class="nv"&gt;$HOST&lt;/span&gt;&lt;span class="s2"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="s2"&gt;Date : &lt;/span&gt;&lt;span class="k"&gt;$(&lt;/span&gt;date&lt;span class="k"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="s2"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="s2"&gt;User : &lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;PAM_USER&lt;/span&gt;&lt;span class="k"&gt;:-&lt;/span&gt;&lt;span class="nv"&gt;N&lt;/span&gt;&lt;span class="p"&gt;/A&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="s2"&gt;Remote User: &lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;PAM_RUSER&lt;/span&gt;&lt;span class="k"&gt;:-&lt;/span&gt;&lt;span class="nv"&gt;N&lt;/span&gt;&lt;span class="p"&gt;/A&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="s2"&gt;Remote Host: &lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;PAM_RHOST&lt;/span&gt;&lt;span class="k"&gt;:-&lt;/span&gt;&lt;span class="nv"&gt;N&lt;/span&gt;&lt;span class="p"&gt;/A&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="s2"&gt;TTY : &lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;PAM_TTY&lt;/span&gt;&lt;span class="k"&gt;:-&lt;/span&gt;&lt;span class="nv"&gt;N&lt;/span&gt;&lt;span class="p"&gt;/A&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="s2"&gt;Service : &lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;PAM_SERVICE&lt;/span&gt;&lt;span class="k"&gt;:-&lt;/span&gt;&lt;span class="nv"&gt;N&lt;/span&gt;&lt;span class="p"&gt;/A&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="s2"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="s2"&gt;## Process Information
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="s2"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="s2"&gt;PID : &lt;/span&gt;&lt;span class="nv"&gt;$$&lt;/span&gt;&lt;span class="s2"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="s2"&gt;Parent PID : &lt;/span&gt;&lt;span class="nv"&gt;$PPID&lt;/span&gt;&lt;span class="s2"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="s2"&gt;Script User: &lt;/span&gt;&lt;span class="k"&gt;$(&lt;/span&gt;id -un&lt;span class="k"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="s2"&gt;Script UID : &lt;/span&gt;&lt;span class="k"&gt;$(&lt;/span&gt;id -u&lt;span class="k"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="s2"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="s2"&gt;## Environment
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="s2"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="s2"&gt;SSH_CLIENT : &lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;SSH_CLIENT&lt;/span&gt;&lt;span class="k"&gt;:-&lt;/span&gt;&lt;span class="nv"&gt;N&lt;/span&gt;&lt;span class="p"&gt;/A&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="s2"&gt;SSH_CONNECTION : &lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;SSH_CONNECTION&lt;/span&gt;&lt;span class="k"&gt;:-&lt;/span&gt;&lt;span class="nv"&gt;N&lt;/span&gt;&lt;span class="p"&gt;/A&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="s2"&gt;SSH_TTY : &lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;SSH_TTY&lt;/span&gt;&lt;span class="k"&gt;:-&lt;/span&gt;&lt;span class="nv"&gt;N&lt;/span&gt;&lt;span class="p"&gt;/A&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="s2"&gt;&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;&lt;/span&gt;&lt;span class="nv"&gt;$MESSAGE&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;&lt;/span&gt; &lt;span class="p"&gt;|&lt;/span&gt; mail -s &lt;span class="s2"&gt;&amp;#34;&lt;/span&gt;&lt;span class="nv"&gt;$SUBJECT&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;&lt;/span&gt;&lt;span class="nv"&gt;$TO&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nb"&gt;exit&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;hr&gt;
&lt;h2 id="make-the-script-executable"&gt;Make the Script Executable&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;chmod +x /usr/local/bin/login-notify.sh
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;hr&gt;
&lt;h2 id="enable-notifications-for-ssh-logins"&gt;Enable Notifications for SSH Logins&lt;/h2&gt;
&lt;p&gt;Edit the SSH PAM configuration:&lt;/p&gt;</description></item><item><title>OpenPGP / GnuPG Cheat Sheet</title><link>https://tlnd.org/Linux/OpenPGP_GnuPG_cheat_sheet/</link><pubDate>Mon, 14 Mar 2016 00:00:00 +0000</pubDate><guid>https://tlnd.org/Linux/OpenPGP_GnuPG_cheat_sheet/</guid><description>&lt;h1 id="a-short-list-of-important-commands-i-use-with-gnupg"&gt;A short list of important commands I use with GnuPG&lt;/h1&gt;
&lt;h2 id="yubikey-and-gnupg-openpgp--gpg"&gt;YubiKey and GnuPG (OpenPGP / gpg)&lt;/h2&gt;
&lt;p&gt;Start with:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;# open the card menu for your YubiKey
gpg --card-edit

# Now enter the admin command
gpg/card&amp;gt; admin

# Now enter help to see all available commands
gpg/card&amp;gt; help
quit quit this menu
admin show admin commands
help show this help
list list all available data
name change card holder&amp;#39;s name
url change URL to retrieve key
fetch fetch the key specified in the card URL
login change the login name
lang change the language preferences
salutation change card holder&amp;#39;s salutation
cafpr change a CA fingerprint
forcesig toggle the signature force PIN flag
generate generate new keys
passwd menu to change or unblock the PIN
verify verify the PIN and list all data
unblock unblock the PIN using a Reset Code
factory-reset destroy all keys and data
kdf-setup setup KDF for PIN authentication
key-attr change the key attribute
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;List all keys on a YubiKey, including their keygrips:&lt;/p&gt;</description></item></channel></rss>