gitlab的密钥配置
- git bash执行下面命令生成ssh公钥和私钥对
ssh-keygen -t rsa -C '你的邮箱' 一路回车
- 查看公钥内容:
cat ~/.ssh/id_rsa.pub
(~用户目录) - 配置远程仓库公钥:个人头像 -> settings -> SSH And GPG Key -> 点击 新增SSH Key按钮 -> 复制公钥
配置多个ssh-key
- 为gitlab生成一对秘钥ssh key
ssh-keygen -t rsa -C '[email protected]' -f ~/.ssh/gitlab-rsa
- 为github生成一对秘钥ssh key
ssh-keygen -t rsa -C '[email protected]' -f ~/.ssh/github-rsa
- 添加私钥
执行ssh-add时提示"Could not open a connection to your authentication agent",可以现执行命令:ssh-add ~/.ssh/gitlab-rsa ssh-add ~/.ssh/github-rsa
再运行ssh-add命令ssh-agent bash # 确私钥列表 ssh-add -l # 清空私钥列表 ssh-add -D exit
- 在
~/.ssh
下touch config
,配置多个不同的ssh key# gitlab Host gitlab.com HostName gitlab.com PreferredAuthentications publickey IdentityFile ~/.ssh/gitlab-rsa # github Host github.com HostName github.com PreferredAuthentications publickey IdentityFile ~/.ssh/github-rsa # Host和HostName填写git服务器的域名,IdentityFile指定私钥的路径
- 测试
ssh -T -v git@[config配置的host值] ssh -T [email protected] ssh -T [email protected] ssh -T [email protected]
Hi stefzhlg! You’ve successfully authenticated, but GitHub does not provide shell access.