惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

aimingoo的专栏
aimingoo的专栏
Google DeepMind News
Google DeepMind News
S
SegmentFault 最新的问题
Project Zero
Project Zero
D
DataBreaches.Net
I
InfoQ
L
Lohrmann on Cybersecurity
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
酷 壳 – CoolShell
酷 壳 – CoolShell
Stack Overflow Blog
Stack Overflow Blog
The Register - Security
The Register - Security
Recorded Future
Recorded Future
Vercel News
Vercel News
博客园 - 司徒正美
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
I
Intezer
The Hacker News
The Hacker News
F
Fortinet All Blogs
Microsoft Azure Blog
Microsoft Azure Blog
P
Proofpoint News Feed
Help Net Security
Help Net Security
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Scott Helme
Scott Helme
T
Threatpost
爱范儿
爱范儿
N
Netflix TechBlog - Medium
D
Docker
云风的 BLOG
云风的 BLOG
C
Cisco Blogs
K
Kaspersky official blog
H
Help Net Security
S
Secure Thoughts
T
Threat Research - Cisco Blogs
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
S
Security @ Cisco Blogs
Cyberwarzone
Cyberwarzone
N
News and Events Feed by Topic
G
Google Developers Blog
Forbes - Security
Forbes - Security
博客园 - 三生石上(FineUI控件)
博客园 - 叶小钗
B
Blog
Google DeepMind News
Google DeepMind News
Recent Announcements
Recent Announcements
Simon Willison's Weblog
Simon Willison's Weblog
S
Securelist
P
Privacy International News Feed
Spread Privacy
Spread Privacy
The Last Watchdog
The Last Watchdog

Dejavu's Blog

甲骨文 ARM 实例部署 Gemma 4 模型 Headscale + Tailscale 组建虚拟专用网 BuyVM VPS 块存储挂载教程 Alpine Linux 服务器配置指南 Alpine Linux 安装 Cloudflared Docker 多容器共享中心数据库 安装 Komari 服务器监控工具 Scaleway VPS 安装 Debian Linux Debian 13 下部署 AsmBB 论坛 使用 Kopia 自动化备份服务器数据 给 Docker 启用 IPv6 支持 Netcup 服务器安装自定义 ISO 镜像 烽火 HG5582A 光猫开启桥接模式 Docker 自托管 Shlink 短链服务 部署 Obsidian LiveSync 实时同步服务指南 我的 2025 年不完全回顾 Linux 下 Intel 核显驱动配置与硬件加速 Fedora Linux 安装配置记录 2025 年优雅地自托管 RSS 服务 Woodpecker CI 和 Gitea 实现 Hugo 自动部署 Gitea/Forgejo 集成 Woodpecker CI/CD 在 Blinko 中使用 Ollama 作为 AI 供应商 Docker 部署 Gitea/Forgejo Plausible CE 启用城市级地理位置识别 Blinko 开源 AI 知识库 Docker 部署指南 Netcup 免税账号注册及购买服务器全记录 Docker 自托管 Cloudreve Pro 私有网盘服务 GiffGaff SIM 卡使用体验和注意事项 简体中文互联网在变得糟糕吗? 如何低成本申请 S/MIME 证书用于个人邮件服务 迁移到 NameCrane Mail 域名邮箱套件服务 香烟与咖啡 在 Windows 中使用 Yubikey 的 OpenPGP 应用 Windows 11 IoT LTSC 养老指南 巧用浏览器生成 HAR 文件批量下载所需网页资源 聊聊静态网站的评论系统 在 Hugo 站点中优雅地展示实况照片 使用 snac 部署一个简洁优雅的 ActivityPub 实例 当 25 岁来临的时候 断网的这两年 从 Bitwarden/Vaultwarden 到 KeePassXC 也许是 Android 上最好的本地播放器 - 椒盐音乐 2023 半年小结 写一个好玩的 Hugo 货币汇率转换短代码 写一个 Hugo 短代码将不同类别的总字数统计转换为书名显示 海信 Touch Lite 墨水屏音乐阅读器的简单体验 从 Debian 11(bullseye) 无感升级到 Debian 12(bookworm) 使用 GitHub Actions 自动提交 URL 到 IndexNow 批量重写 Git 历史提交记录 使用 cgit 托管小小的也很可爱的 Git 服务器 在 Debian 上使用 stagit 和 Nginx 的简单 Git 服务器 托管简单 Git 服务器的一些尝试 使用 stagit 自托管纯静态 Git 存储库 使用 Docker 快速部署单人 Fediverse 实例 我是如何建立自己的个人博客的? 简单、隐私友好的谷歌分析替代品,Plausible 自托管部署指南 服务器使用 Cloudflare CDN 的最佳实践 甲骨文服务器分配并启用 IPv6 地址 Git 版本控制学习笔记(二) Cloudflare WAF 防护策略简易指南 Mastodon 服务器批量导入自定义表情 低成本自托管 Mastodon 实例简明指南 自托管服务指南──有了服务器可以做什么? 使用 Miniflux + RSSHub 打造个人 RSS 阅读器 构建支持多种 CPU 架构的 Docker 镜像 一个可自托管的静态短链接应用 别了,二〇二二! Duplicacy CLI 进阶使用指南 Duplicacy CLI 备份工具的基本使用 初探 Cloudflare 零信任 - 通过 Docker 部署 Bitwarden 密码管理器 Yubikey 转运日志及上手指南 初探 Cloudflare 零信任 — 通过 Cloudflare Tunnel 搭建 SSH 聊天室 初探 Cloudflare 零信任 - 通过 Cloudflare Tunnel 访问服务 某科学的 PGP 算号指南 2022 年的 MacBook Air M1 使用体验及应用推荐 使用 Vercel 和 Supabase 自托管 Cusdis 评论系统 为什么你的搜索引擎不好用? 个人在 Windows 上常用软件清单 macOS 基础开发环境设置指南 在 macOS 上使用 Canokey 的 OpenPGP 应用 提取 Windows UWP 应用商店的安装包以供离线安装 Git 版本控制学习笔记(一) 使用 Notion 管理 GitHub Star 项目 使用 Vercel 免费部署 Giscus 评论系统 将博客评论从 Utterances 无缝迁移到 Giscus Canokey 签名和认证应用指南 Canokey 的基本使用指南 Canokey Pigeon 揽件日志及简单开箱 关于 Google Play 保护机制和 DRM 安全等级的那些事 记录一次捡垃圾装机 GitHub 使用 GPG 密钥提交签名认证 使用 Scoop 管理 Windows 下的软件和开发环境 Windows Terminal+PowerShell 7 打造 Windows 下最好用的终端 一个好用的 Telegram 文件批量上传/下载工具 Clash for Windows 优雅地使用 TUN 模式接管系统流量 全平台搭建 Hexo 静态博客指南 尝试将 Manjaro 作为主力操作系统使用 Hexo 进行 SEO 优化的基本指南 使用本地代理给 Git 和 NPM 加速 使用 flowerss 部署 Telegram RSS 订阅机器人
在 Linux 上使用 Yubikey OpenPGP 应用
Dejavu Moe · 2026-04-04 · via Dejavu's Blog

引言

跨平台使用 Yubikey OpenPGP 的步骤大同小异,之前已经写了:

本文以 Fedora Workstation 43 (GNOME 桌面环境) 为例,作为 Linux 桌面上使用步骤的补充说明,方便我在新系统上快速设置。

环境准备

[可选] 若需查看 2FA 口令或简单管理 Yubikey,可通过 Flatpak 安装 Authenticator:

flatpak install flathub com.yubico.yubioath

安装 OpenPGP 智能卡相关的核心组件:

sudo dnf install gnupg \
  pcsc-lite \
  pcsc-lite-ccid \
  gnupg2-scdaemon \
  pcsc-tools

启动服务:

sudo systemctl enable --now pcscd

导入 PGP 公钥

和往常一样,在新系统上导入你的 PGP 公钥并设置信任:

# 这是我的 PGP 公钥
curl -fsSL https://pgp.dejavu.moe/ | gpg --import -
# 导入通用配置
wget https://raw.githubusercontent.com/drduh/YubiKey-Guide/master/config/gpg.conf -O ~/.gnupg/gpg.conf
chmod 600 ~/.gnupg/gpg.conf

配置 Git 签名信息:

git config --global user.name <username>
git config --global user.email <email>
git config --global user.signingkey <keyid>
git config --global commit.gpgsign true
git config --global gpg.program /usr/bin/gpg

配置 GPG 服务

检查系统中可用的 pinentry(密码输入)程序:

ls -lh /usr/bin/ | grep pinentry        
-rwxr-xr-x. 1 root root     2.4K Jul 28  2025 pinentry
-rwxr-xr-x. 1 root root      77K Jul 28  2025 pinentry-curses
-rwxr-xr-x. 1 root root      89K Jul 28  2025 pinentry-gnome3

为了在终端和图形化应用中都能获得最佳使用体验,建议通过脚本实现 pinentry 切换器:检测到 TTY 时调用 pinentry-curses,否则调用 pinentry-gnome3

vim ~/.gnupg/pinentry-wrapper.sh

写入判断逻辑:

#!/bin/bash
if [ "$PINENTRY_USER_DATA" = "curses" ]; then
    exec /usr/bin/pinentry-curses "$@"
else
    exec /usr/bin/pinentry-gnome3 "$@"
fi

编辑 gpg-agent.conf 配置文件:

vim ~/.gnupg/gpg-agent.conf

填入以下配置(路径中用户名替换为实际名称):

#ttyname $GPG_TTY
enable-ssh-support
allow-loopback-pinentry
# 指定自定义包装脚本,必须使用绝对路径
pinentry-program /home/dejavu/.gnupg/pinentry-wrapper.sh
# 或者选择你期望的 pinentry 程序
#pinentry-program /usr/bin/pinentry-curses
#pinentry-program /usr/bin/pinentry
#pinentry-program /usr/bin/pinentry-qt
#pinentry-program /usr/bin/pinentry-gnome3
#pinentry-program /usr/bin/pinentry-tty
#pinentry-program /usr/bin/pinentry-x11
# 缓存有效期设置(单位:秒)
default-cache-ttl 3600
max-cache-ttl 7200
default-cache-ttl-ssh 3600
max-cache-ttl-ssh 7200

查看认证子密钥的 KeyGrip 并写入 ~/.gnupg/sshcontrol

# 查看 KeyGrip
gpg -K --with-keygrip

对于 ~/.gnupg/scdaemon.conf:尽管 Yubikey Guide 中建议开启,但在实测中这可能会导致缓存失效,导致每次签名/认证都需要输入 PIN。

若遇到此类问题,建议注释相关选项:

#disable-ccid
#pcsc-shared

环境变量配置

将以下内容追加到 Shell 配置文件(.bashrc.zshrc)中:

# SSH GPG Agent for Yubikey
export GPG_TTY=$(tty)
export SSH_AUTH_SOCK=$(gpgconf --list-dirs agent-ssh-socket)
gpgconf --launch gpg-agent
export PINENTRY_USER_DATA="curses"
gpg-connect-agent updatestartuptty /bye > /dev/null

然后根据 Shell 的类型,执行:

source ~/.zshrc
# 或者
source ~/.bashrc

最后重启相关服务,使配置生效:

sudo systemctl stop pcscd pcscd.socket && sudo systemctl start pcscd.socket
gpgconf --kill all && gpgconf --launch gpg-agent

功能测试

重新插入 Yubikey,验证智能卡是否被正常识别:

执行签名测试,检查 PIN 输入窗口:

echo "test" | gpg --clearsign

在终端里预期调用的是 pinentry-curses,就像这样:

test.webp

最后,验证 SSH 公钥读取及认证功能:

至此,Linux 平台上的 Yubikey OpenPGP 环境配置完成。