Git使用SSH密钥来签名commit
一、生成SSH密钥推荐使用 Ed25519 算法(更安全)
ssh-keygen -t ed25519 -C "your_email@example.com"或使用 RSA 算法(兼容性更好)
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"二、上传SSH公钥
注:Authentication Key和Signing Key可以使用同一个密钥添加
Github选择签名密钥
三、配置Git使用SSH密钥
注:公钥文件的位置不能有更改
全局设置
git config --global gpg.format ssh
git config --global user.signingkey <public_key>当前仓库设置
git config gpg.format ssh
git config user.signingkey <public_key>签名
手动签名
git commit -S -m "Your signed commit message"自动签名
全局设置
git config --global commit.gpgsign true当前仓库设置
git config commit.gpgsign true四、设置多个SSH密钥
创建
在路径%USERPROFILE%\.ssh文件夹下创建config文件
手动创建或使用git Bash运行命令
touch config配置
# github
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/github_key
# github
Host github2.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/github2_key
# gitee
Host gitee.com
HostName gitee.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/gitee_keyHost 别名,用户命令行使用
HostName 托管平台服务器地址
PreferredAuthentications 权限认证(publickey,password,publickey,keyboardinteractive)
IdentityFile 证书文件位置
测试
ssh -t git@github.com
ssh -t git@github2.com
ssh -t git@gitee.com
来源:程序园用户自行投稿发布,如果侵权,请联系站长删除
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!
页:
[1]