查看本机是否已经生成ssh key, 如果已存在,不需要移除。(其他网页都是需要删除重新生成,这样原来的项目都得重新操作一遍)
第一个生成git sshkey(略),直接第二个
$ ssh-keygen -t rsa -C "your_email@email.com" -f ~/.ssh/id_rsa_gitlab
配置ssh代理
// 查看系统ssh-key代理
$ ssh-add -l
--------------- 如果已经添加过,也可以不删除原有,直接增加新的
windows添加ssh-key时应用ssh-add 报错,则应启动 ssh agent bash
$ ssh-add ~/.ssh/id_rsa_gitlab
Could not open a connection to your authentication agent.
$ ssh-agent bash
---------------
// 在 .ssh 目录创建 config 配置文件
配置文件config添加以下内容
#github配置
Host github.com
HostName github.com
IdentityFile C:\Users\Administrator\.ssh\id_rsa
PreferredAuthentications publickey
User git
#gitlab的配置
Host gitlab.XXX.com
HostName gitlab.XXX.com
IdentityFile C:\Users\Administrator\.ssh\id_rsa_gitlab
PreferredAuthen

本文介绍了在Windows环境下如何在已有SSH密钥的基础上生成多个Git SSH密钥,用于不同Git服务,如GitHub和GitLab。通过ssh-keygen创建新密钥,配置ssh-agent和~/.ssh/config文件,以及解决重新打开命令行时连接丢失的问题。同时提到了在不同仓库设置局部用户名和邮箱的必要性。
最低0.47元/天 解锁文章
3722

被折叠的 条评论
为什么被折叠?



