Windows 上使用 SSH 签名 Git 提交记录
Published
•1 min read
前提
生成新 SSH 密钥并复制
ssh-keygen -t ed25519 -C "your_email@example.com"
clip < ~/.ssh/id_ed25519.pub
将结果添加到 GitHub 的 SSH and GPG keys 中。
将 SSH 密钥添加到 ssh-agent
- 确保 ssh-agent 正在运行
eval "$(ssh-agent -s)"
- 将 SSH 私钥添加到 ssh-agent
ssh-add ~/.ssh/id_ed25519
使用 SSH 签名
- 全局使用 SSH 签名
git config --global gpg.format ssh
- 指定 SSH 签名使用文件
git config --global user.signingKey ~/.ssh/id_ed25519.pub
- 在 .ssh 目录新建一个可信公钥列表文件
allowed_signers, 内容为id_ed25519.pub前面加上邮箱
touch ~/.ssh/allowed_signers && clip < ~/.ssh/id_ed25519.pub
echo "your_email@example.com 粘贴到这" >> ~/.ssh/allowed_signers
例如我的列表文件 allowed_signers
tobychung@duck.com ssh-ed25519 AAAA(...已省略)RuQj tobychung@duck.com
- 指定可信公钥列表文件
git config --global gpg.ssh.allowedSignersFile ~/.ssh/allowed_signers
- 开启全局自动签名
git config --global commit.gpgsign true
git config --global tag.gpgsign true
测试现有仓库
git commit --allow-empty --message="Testing SSH signing"
查看签名
git log --show-signature -3
这个时候我们就可以看到第一条有Good "git" signatures ...验证消息了。
GitHub 认证标识
点击账号设置 SSH and GPG keys 中勾选 Vigilant mode 使用 SSH 签名 Git 提交记录/勾选认证.png)
再次添加相同的公钥重点 Key type 要选择 signing key 即可。
clip < ~/.ssh/id_ed25519.pub
