This commit is contained in:
@@ -126,11 +126,31 @@ ssh-keygen -t ed25519-sk -O resident -O verify-required -O application=ssh:<name
|
||||
方法一: 使用 `ssh-copy-id`
|
||||
|
||||
``` bash
|
||||
ssh-copy-id -i /path/to/public-key.pub [username]@[server_ip]
|
||||
ssh-copy-id -i /path/to/key.pub [username]@[server_ip]
|
||||
```
|
||||
|
||||
方法二: 将公钥内容插入服务器 `~/.ssh/authorized_keys` 文件的末尾
|
||||
|
||||
**将公钥添加至 GitHub**:
|
||||
|
||||
- 将密钥作为 SSH 密钥上传至 GitHub: SSH 公钥必须添加到 GitHub 账户的 SSH 和 GPG 密钥设置。
|
||||
- 前往 GitHub > 设置 > SSH 和 GPG 密钥。
|
||||
- 点击“添加 SSH 密钥”。
|
||||
- 粘贴您的公钥。
|
||||
|
||||
修改 `/path/to/.ssh/config`
|
||||
|
||||
``` title="~/.ssh/config"
|
||||
Host github.com
|
||||
HostName ssh.github.com
|
||||
User git
|
||||
Port 443
|
||||
PreferredAuthentications publickey
|
||||
IdentityFile "/path/to/.ssh/key"
|
||||
```
|
||||
|
||||
测试能否正常连接: `ssh -T git@github.com`
|
||||
|
||||
**在新设备上使用常驻密钥**:
|
||||
|
||||
常驻密钥具有便携性,可以轻松取回私钥句柄和公钥文件。
|
||||
@@ -147,7 +167,93 @@ ssh-keygen -K
|
||||
|
||||
### 使用 PicoKeys 与 SSH/FIDO2 进行 Git 提交签名
|
||||
|
||||
https://zhuanlan.zhihu.com/p/691575345
|
||||
检查 OpenSSH 版本,建议为 OpenSSH 8.3 或以上。检查 Git 版本,建议为 Git 2.34 或以上。
|
||||
|
||||
``` bash
|
||||
ssh -V
|
||||
|
||||
git --version
|
||||
```
|
||||
|
||||
**设置 Git 默认用户名与邮箱**:
|
||||
|
||||
此处设置的邮箱必须与在 GitHub/GitLab/Gitea 中设置的一致。
|
||||
|
||||
``` bash
|
||||
git config --global user.name "username"
|
||||
git config --global user.email "your.email@example.com"
|
||||
```
|
||||
|
||||
**生成 ed25519-sk 密钥**:
|
||||
|
||||
``` bash
|
||||
ssh-keygen -t ed25519-sk -O resident -O verify-required -O application=ssh:git-signing -O user=<name> -C "Git Signing Key"
|
||||
```
|
||||
|
||||
**为 Git 配置 SSH 签名**:
|
||||
|
||||
将 Git 的 GPG 格式设置为 SSH:
|
||||
|
||||
``` bash
|
||||
git config --global gpg.format ssh
|
||||
```
|
||||
|
||||
指定签名密钥(公钥):
|
||||
|
||||
``` bash
|
||||
git config --global user.signingkey /path/to/your/git-signing-key-public.pub
|
||||
```
|
||||
|
||||
启用自动提交签名和自动标签签名:
|
||||
|
||||
``` bash
|
||||
git config --global commit.gpgSign true
|
||||
git config --global tag.forceSignAnnotated true
|
||||
```
|
||||
|
||||
**创建并配置 allowed_signers 文件**:
|
||||
|
||||
`allowed_signers` 文件每行的格式为: `[email] namespaces="git" [git_signing_public_key_string]`
|
||||
|
||||
例如:
|
||||
|
||||
``` title="allowed_signers"
|
||||
your.email@example.com namespaces="git" ssh-ed25519 AAAAC3NzaC1lZYourPublicKeyData... Git Signing Key
|
||||
```
|
||||
|
||||
请确保 `your.email@example.com` 与在 `git config user.email` 设置的邮箱完全匹配。`namespaces="git"` 对于限定密钥权限范围至关重要。
|
||||
|
||||
在 Git 中设定 `allowed_signers` 文件的位置:
|
||||
|
||||
``` bash
|
||||
git config --global gpg.ssh.allowedSignersFile /path/to/your/.ssh/allowed_signers"
|
||||
```
|
||||
|
||||
**本地验证签名情况**:
|
||||
|
||||
- 针对提交: `git log --show-signature`
|
||||
- 针对标签: `git tag -v <tag-name>`
|
||||
- 查看是否有 `Good "git" signature for your.email@example.com with ED25519-SK key ...`
|
||||
|
||||
**在 GitHub 与 Gitea 上获取“已验证”标志**:
|
||||
|
||||
GitHub:
|
||||
|
||||
- 将您的签名密钥作为 SSH 密钥上传至 GitHub: 用于签名的 SSH 公钥必须以认证密钥的形式添加到 GitHub 账户的 SSH 和 GPG 密钥设置。
|
||||
- 前往 GitHub > 设置 > SSH 和 GPG 密钥。
|
||||
- 点击“添加 SSH 密钥”。
|
||||
- 粘贴您的签名公钥。
|
||||
- GitHub 会将此密钥生成的签名与您的账户关联,并在**提交者邮箱与 GitHub 账户已验证邮箱匹配**时,将提交标记为“已验证”。
|
||||
|
||||
Gitea:
|
||||
|
||||
- 将您的签名密钥作为 SSH 密钥上传至 Gitea: 用于签名的 SSH 公钥必须以认证密钥的形式添加到 Gitea 账户的 SSH 和 GPG 密钥设置。
|
||||
- 前往 Gitea > 设置 > SSH 和 GPG 密钥。
|
||||
- 点击“添加 SSH 密钥”。
|
||||
- 粘贴您的签名公钥。
|
||||
- 点击“验证”按钮,[按照提示验证公钥](https://blog.cattom.site/tech/Snippets/#gitea)。
|
||||
- Gitea 会将此密钥生成的签名与您的账户关联,并在**提交者邮箱与 Gitea 账户已验证邮箱匹配**时,将提交标记为“已验证”。
|
||||
|
||||
|
||||
## PicoKeys 指示灯
|
||||
|
||||
|
||||
Reference in New Issue
Block a user