需要配多个git账号,每次都查来查去,特此记录。
生成公钥:
ssh-keygen -t rsa -C '你的邮箱地址'
为了更好区分,修改别名
如果发现并未生成在ssh目录,是因为默认生成在了C:\Users\用户名路径下,
打开cmd cd .ssh后再生成即可。
配置多个时记得取消设置全局用户名,邮箱 (可先忽略,有问题再来设置)
git config --global --unset user.name
git config --global --unset user.email
之后提交设置项目范围的即可
git config user.name "Your Name"
git config user.email "Your email"
然后添加后的id_gitee.pub中的内容复制到gitee ssh秘钥中添加即可
ssh -T git@gitee.com
config文件内容如图所示 其他的按照此格式写即可
公司内部的比较麻烦
# gitee
Host gitee.com # 代表github的git代码仓库地址
HostName gitee.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_gitee
# 公司内部 如gitlab Host HostName均为公司仓库地址即可
Host xxx.com
HostName xxx.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_company