Mac多Git账号配置

文章目录
  1. 1. 准备两个Git账号,如Github账号和Gitee账号
  2. 2. 在用户家目录下新建.ssh目录,进入目录后新建config文件
  3. 3. 使用ssh-keygen -t rsa -C “xxxxx@xxxxx.com“,生成ssh key
  4. 4. 将id_rsa_gitee.pub的公钥配置到gitee上的ssh公钥配置
  5. 5. 在config文件中配置pub文件
  6. 6. 配置测试

准备两个Git账号,如Github账号和Gitee账号

在用户家目录下新建.ssh目录,进入目录后新建config文件

使用ssh-keygen -t rsa -C “xxxxx@xxxxx.com“,生成ssh key

单个git账号配置时,不需要指定publicKey文件名,但是多个git账号配置,就需要指定文件名
1
2
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/chenmin/.ssh/id_rsa): id_rsa_github
其他配置项继续回车即可
1
2
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文件

1
2
3
4
Host user
HostName https://github.com
User user
IdentityFile ~/.ssh/id_rsa_github

注:
HostName是服务器的地址,User是用户名,PreferredAuthentications照抄即可,这里主要说的是IdentityFile

配置测试

1
ssh -T git@gitee.com

显示 Welcome to Gitee.com, yourname! 时则表示配置成功
若报错或不是这个结果,可使用

1
ssh -vT git@gihub.com

查看错误信息,并使用下面的命令解决

1
2
ssh-agent bash
ssh-add ~/.ssh/id_rsa

关注我的微信公众号:FramePower
我会不定期发布相关技术积累,欢迎对技术有追求、志同道合的朋友加入,一起学习成长!


微信公众号

如果文章对你有帮助,欢迎点击上方按钮打赏作者