前言
YubiKey是什么东西我就不多说,简单的说是一种用来保存私钥的硬件设备,私钥一旦写入就无法读出,比起保存在硬盘里的私钥文件,更安全。前段时间入手一个YubiKey 5 NFC,最近一直在研究怎么用来登录SSH。
需求
我手上已经有了一个SSH密钥对用来管理着几十台Linux服务器,,在Yubikey Mmanager
-> PIV
中只能重新生成密钥对,并且无法导出私钥,然而我不想更换的我的私钥,与我的需求不符。在入手后的10天的里,每天都在研究怎么搞定这个问题……google都快翻烂了。
解决
1.将PGP密钥写入SmartCard智能卡
我是先用GnuPG4win生成PGP密钥对,然后导入SSH私钥,替换掉PGP密钥的Auth子密钥。
具体过程就不细说了,可以参考下方的资料。
注意,操作前先备份好密钥,下面步骤会将私钥写入卡上,并且无法导出!!!
大概流程:
c:\>gpg -a --export-secret-keys [user-id] > [user-id].asc
c:\>gpg --edit-key [user-id]
gpg (GnuPG) 2.2.27; Copyright (C) 2021 g10 Code GmbH
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Secret key is available.
sec rsa2048/****************
created: 2021-03-22 expires: never usage: SC
trust: ultimate validity: ultimate
ssb rsa2048/****************
created: 2021-03-22 expires: never usage: E
card-no: 000615524
ssb rsa2048/****************
created: 2021-03-22 expires: never usage: S
card-no: 000615524
ssb rsa2048/****************
created: 2021-03-24 expires: never usage: A
card-no: 000615524
[ultimate] (1). sbdx