github添加多个账号

git push命令:

git remote add origin {远程地址}
git push origin master



新建user1、user2的SSH Key

#新建user1 SSH key:

$ cd ~/.ssh    

# 切换到C:\Users\Administrator\.ssh

#ssh-keygen -t rsa -C "user1@email.com"

一路回车即可;

 # 新建user2的SSH key

#ssh-keygen -t rsa -C "user2@email.com"

# 设置名称为Enter file in which to save the key (/c/Users/Administrator/.ssh/id_rsa): /c/Users/Administrator/.ssh/id_rsa_user2

接下来一路回车不设置密码

密钥添加到SSH agent中

因为默认只读取id_rsa,为了让SSH识别新的私钥,需将其添加到SSH agent中:

ssh-add ~/.ssh/id_rsa_user2

如果出现Could not open a connection to your authentication agent的错误,就试着用以下命令:

eval `ssh-agent -s`
ssh-add ~/.ssh/id_rsa_user2

将ssh key 添加到github账号中
clip< ~/.ssh/id_rsa_user2.pub  拷贝sshkey到剪切板
打开github网页,添加ssh key,复制进去。


修改config文件

 在~/.ssh目录下找到config文件,如果没有就创建:

touch config    

然后修改我的config配置如下:

Host github.com
    HostName github.com
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/id_rsa

Host github2
    HostName github.com
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/id_rsa_user2

测试

$ ssh -T git@github.com

Hi XXXX! You've successfully authenticated, but GitHub does not provide shell access.

 $ ssh -T git@github2

Hi XXXX! You've successfully authenticated, but GitHub does not provide shell access.


--------------------------PS ---------------------
用以上方法成功使用上了自己的Github账号clone项目,但是两条都提示的是我自己的账号,明明设置了其中一个是工作账号的。。。。不过好在工作账号也没啥需要访问上去的必要。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值