mac 一台电脑两个github账号

mac 一台电脑两个github账号

自己有两个github账号,要配置在同一台笔记本上

个人账号:itxingOne@163.com

公司账号:itxingTwo@163.com

假设个人账号已经配置,现在添加公司账号itxingTwo@163.com

1.配置账号

$ git config --global user.name "itxingTwo"

$ git config --global user.email "itxingTwo@163.com"

2.生成ssh密钥

$ ssh-keygen -t rsa -C "itxingTwo@163.com"

3.设置名称为id_rsa_two(名称随意)

$ Enter file in which to save the key (/Users/Administrator/.ssh/id_rsa): id_rsa_two

4.新密钥添加到SSH agent中

$ ssh-agent bash

$ ssh-add ~/.ssh/id_rsa_two

5.创建一个config文件,必须先进入ssh目录下创建

$ cd ~/.ssh

$ touch config

6.在config中配置你使用的git

Host github.com

  HostName github.com

  IdentityFile ~/.ssh/id_rsa

Host github_two

  HostName github.com

  IdentityFile ~/.ssh/id_rsa_two

7.将id_rsa_two.pub中的内容添加到gitlab帐号下的SSH Key中

8.添加SSH Key后进行测试是否连接成功

$ ssh -T github.com

成功则

Welcome to Git@xxxx, yourname!

失败则

Permission denied (publickey).

解决方案

$ ssh-add ~/.ssh/id_rsa_two

一切风平浪静,努力学习吧

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容