一台电脑上使用两个GitHub账户

使用ssh-keygen生成两个ssh key,目录内容如下:

$ ll ~/.ssh/
total 15
-rw-r--r-- 1 Cui 197121  336 九月 15 10:25 config
-rw-r--r-- 1 Cui 197121 1675 七月 19 22:56 id_rsa
-rw-r--r-- 1 Cui 197121  398 七月 19 22:56 id_rsa.pub
-rw-r--r-- 1 Cui 197121 1675 九月 15 00:09 id_rsa_other
-rw-r--r-- 1 Cui 197121  398 九月 15 00:09 id_rsa_other.pub
-rw-r--r-- 1 Cui 197121 1989 九月 12 21:57 known_hosts

ssh的config文件如下:

$ cat ~/.ssh/config
# one

    Host github.com

    HostName github.com

    PreferredAuthentications publickey

    IdentityFile ~/.ssh/id_rsa

    User legend9207

# two

    #远程主机地址别名;git config中远程git服务地址可以配置成这个,以达到相同git服务地址使用不同ssh key的目的。
    Host cuiyindeng.github.com

    HostName github.com

    PreferredAuthentications publickey

    IdentityFile ~/.ssh/id_rsa_other

    User cuiyindeng

两个项目的git config文件如下:

项目1目录/.git/config
...
[remote "origin"]
	url = git@github.com:legend9207/legend9207.github.io.git
	fetch = +refs/heads/*:refs/remotes/origin/*
...

项目2目录/.git/config
...
[remote "origin"]
    #此时的git服务地址用的是ssh config中的别名。
	url = git@cuiyindeng.github.com:cuiyindeng/cuiyindeng.github.io.git
	fetch = +refs/heads/*:refs/remotes/origin/*
...

参考文章:https://blog.csdn.net/wolfking0608/article/details/78512171

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值