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

推荐订阅源

T
Threat Research - Cisco Blogs
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
月光博客
月光博客
V
Vulnerabilities – Threatpost
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
S
Secure Thoughts
Microsoft Azure Blog
Microsoft Azure Blog
Blog — PlanetScale
Blog — PlanetScale
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
T
Tailwind CSS Blog
S
SegmentFault 最新的问题
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
云风的 BLOG
云风的 BLOG
The Last Watchdog
The Last Watchdog
L
LINUX DO - 热门话题
酷 壳 – CoolShell
酷 壳 – CoolShell
WordPress大学
WordPress大学
AWS News Blog
AWS News Blog
美团技术团队
G
Google Developers Blog
宝玉的分享
宝玉的分享
www.infosecurity-magazine.com
www.infosecurity-magazine.com
C
CXSECURITY Database RSS Feed - CXSecurity.com
Recent Commits to openclaw:main
Recent Commits to openclaw:main
I
InfoQ
小众软件
小众软件
Google DeepMind News
Google DeepMind News
P
Privacy & Cybersecurity Law Blog
Stack Overflow Blog
Stack Overflow Blog
Webroot Blog
Webroot Blog
D
DataBreaches.Net
IT之家
IT之家
PCI Perspectives
PCI Perspectives
人人都是产品经理
人人都是产品经理
Hacker News: Ask HN
Hacker News: Ask HN
L
LangChain Blog
SecWiki News
SecWiki News
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Cisco Blogs
T
Threatpost
P
Proofpoint News Feed
Y
Y Combinator Blog
Cloudbric
Cloudbric
T
Tor Project blog
量子位
博客园_首页
B
Blog
Hugging Face - Blog
Hugging Face - Blog
GbyAI
GbyAI
D
Darknet – Hacking Tools, Hacker News & Cyber Security

K.I.S.S

身在 Kimi 的 800 天 写在 Kimi K2 发布之后:再也不仅仅是 ChatBot macOS 按域名切换 DNS 解析 | K.I.S.S 为什么说 GPT 是无损压缩 | K.I.S.S 握着你的手训一个类GPT语言模型 (二) | K.I.S.S 握着你的手训一个类GPT语言模型 (一) | K.I.S.S Rosetta in Linux Virtual Machine on Apple Silicon Fit an Overfit with MegEngine 把 CUPS 扔进 docker 里 ASUS Chromebook Flip | K.I.S.S 使用 dnsmasq 和 ipset 的策略路由 YubiKey 4 简介与配置 | K.I.S.S 定制GH60机械键盘 | K.I.S.S Debian 网络安装内核参数 | K.I.S.S 我的 Vim 配置 | K.I.S.S Libinput 与 Udev | K.I.S.S 给妹子看的 Arch Linux 桌面日常安装 | K.I.S.S 修复GTK3 CSD外观 | K.I.S.S 握着你的手教你画哀女王 | K.I.S.S R.I.P Google Reader | K.I.S.S Richard Stallman仍然是对的 | K.I.S.S Scala 自定义控制结构 | K.I.S.S 入手Wacom Bamboo CTL470 | K.I.S.S 转个型? | K.I.S.S Wish List | K.I.S.S pulseaudio音量问题 | K.I.S.S 入手yubikey,一点小心得 | K.I.S.S 迁移到Octopress | K.I.S.S 自动更新DNSPod记录 | K.I.S.S Linux 用作 IPv6 网关 | K.I.S.S Conky从豆瓣获取MPD专辑封面 | K.I.S.S 我和Linus大学时那些事儿 | K.I.S.S Micro$oft依然是那副老德行 | K.I.S.S 用PulseAudio TCP Forwarding实现网络传声 | K.I.S.S 利用tmpfs加速gnome-shell overview模式Applications索引 | K.I.S.S 新的短网址 | K.I.S.S 紧张的一个月 | K.I.S.S 5月11日活动有感 | K.I.S.S 西电开源社区2011年Tee 最终版 | K.I.S.S 多头多尾的Linux | K.I.S.S Linux的中文名称怎么翻译呢? | K.I.S.S iPhone使用OpenVPN | K.I.S.S 我的人人网敏感词 | K.I.S.S 纪念钱立生老师 | K.I.S.S twitter键盘控:Twittperator | K.I.S.S 天生的暴力倾向? | K.I.S.S The Open Source Spirit | K.I.S.S Libreoffice | K.I.S.S Hello world! | K.I.S.S Python 调用gnuplot的例子 | K.I.S.S The Beginning | K.I.S.S About Me | K.I.S.S
GPG 与 SSH Agent 转发
2016-07-30 · via K.I.S.S

我一直有这样的问题,当我 SSH 到某个远程主机时,就很难进一步进行 SSH 和 GPG 相关操作,因为远端没有我的私钥,如果直接把私钥拷贝到远程,则非常不安全。 自从有了yubikey之后,这个问题更加严重:私钥在 yubikey 里,根本不可能“拷贝到远程”。

过去我的一些做法是使用 usbip,相当于把 yubikey “挂载”到远程的机器上,这个太 hacky 了,并且配置麻烦,不灵活。

直到我发现了 SSH 已经可以转发 UNIX Domain Socket。

首先 SSH Agent 的转发非常简单,只要你使用 SSH Agent 保存密钥,那么用 ssh -A 连接主机,或者在 ~/.ssh/config 里写上 ForwardAgent yes 即可。

GPG Agent 的转发相对麻烦一些,版本要求是: OpenSSH >6.7 以及 GnuPG >2.1 。

首先,本地的 GPG Agent 要加上 --extra-socket 选项,用于 SSH 转发。文档的解释是:

–extra-socket name

Also listen on native gpg-agent connections on the given socket. The intended use for this extra socket is to setup a Unix domain socket forwarding from a remote machine to this socket on the local machine. A gpg running on the remote machine may then connect to the local gpg-agent and use its private keys. This allows to decrypt or sign data on a remote machine without exposing the private keys to the remote machine.

一般在 ~/.gnupg/gpg-agent.conf 里加上 extra-socket /path/to/extra/socket 就好。

然后使用 SSH Remote Forwarding 将远端 socket 转发到本地,也就是让 SSH 在把远程主机的一个 unix socket 转发到本地 GPG Agent 监听的 extra socket 上即可。 这里需要注意几点:

  1. GPG 2.1 之后,不再使用 GPG_AGENT_INFO 环境变量,而是一定会连接 $GNUPGHOME/S.gpg-agent (一般是 ~/.gnupg/S.gpg-agent)。
  2. GPG 2.1.13 之后,如果存在 /run/user/$UID/gnupg 目录, 则会把 gpg-agent 的 socket 放过去,如果不存在,则 fallback 到 $GNUPGHOME 里。
  3. 如果远端已经跑着一个 gpg-agent 了,就需要先关掉,否则 ssh 就无法监听需要转发的 socket 了

所以,使用以下命令进行 SSH 连接,才能成功转发 gpg agent

ssh -R /run/user/REMOTE_UID/gnupg/S.gpg-agent:/path/to/S.gpg-agent.extra \
    -o StreamLocalBindUnlink=yes user@example.com

这里的 StreamLocalBindUnlink 是让 ssh 连接断开的时候,把远端监听的 socket unlink 掉,不然下次连接就会转发失败了。

这个参数比较长,很麻烦,所以也可以在 ~/.ssh/config 里加上

StreamLocalBindUnlink yes
RemoteForward /run/user/REMOTE_UID/gnupg/S.gpg-agent /path/to/S.gpg-agent.extra

亲测,在使用 yubikey 的情况下,远程主机可以正常进行签名、解密等操作,但是gpg --card-edit是被禁止的。

p.s. 测试的时候,确保远端没有 gpg-agent 在运行,执行一下 gpg-connect-agent /bye, 如果提示说 no running gpg-agent - starting '/usr/bin/gpg-agent' 就说明转发失败了。

以上。