Mac多Git账号配置
2018-12-18 本文已影响5人
梦中一点心雨
在开发的过程中,难免会在多个代码平台(Github、Gitee)上提交代码,传统的Git账号配置就比较麻烦了,此文对Mac系统下的多git账号配置进行介绍。
准备两个Git账号,如Github账号和Gitee账号
在用户家目录下新建.ssh目录,进入目录后新建config文件
使用ssh-keygen -t rsa -C "xxxxx@xxxxx.com",生成ssh key
单个git账号配置时,不需要指定publicKey文件名,但是多个git账号配置,就需要指定文件名
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/chenmin/.ssh/id_rsa): id_rsa_github
其他配置项继续回车即可
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/chenmin/.ssh/id_rsa): id_rsa_gitee
此时会在.ssh目录下看到四个文件,id_rsa_github、id_rsa_github.pub和id_rsa_gitee、id_rsa_gitee.pub
将id_rsa_gitee.pub的公钥配置到gitee上的ssh公钥配置
在设置 —> 安全设置 —> SSH公钥,然后将id_rsa_gitee.pub中的内容复制到公钥处,点击确定即可。
github类似。
在config文件中配置pub文件
Host user
HostName https://github.com
User user
IdentityFile ~/.ssh/id_rsa_github
注:
HostName是服务器的地址,User是用户名,PreferredAuthentications照抄即可,这里主要说的是IdentityFile
配置测试
ssh -T git@gitee.com
显示 Welcome to Gitee.com, yourname! 时则表示配置成功
若报错或不是这个结果,可使用
ssh -vT git@gihub.com
查看错误信息,并使用下面的命令解决
ssh-agent bash
ssh-add ~/.ssh/id_rsa