git添加双账号


之前也没这么弄过,不过最近github上写点东西,所以找了一下怎么弄。

安装git什么的就不说了。

1.设置github ssh

打开gitbase,

$ ssh-keygen -t rsa -C "youremail@gmail.com"
Generating public/private rsa key pair.
Enter file in which to save the key (~/.ssh/id_rsa): id_rsa_github
Enter passphrase (empty for no passphrase):

这时会在./.ssh/目录一下有一个id_rsa_github.pub文件

$ cat id_rsa_github.pub

查询出公钥,

ssh-rsa
AAAAB3NzaC1yc2EAAAADAQABAAABgQCrIS7gPefwWaijTsmNKUib29KIkcP+tzrH/wtOtHZg/kh5QDBp68ph8wa4QnPIL9r0h32wOVK5jhNEf4+Vj4M8a0DRwrpoCzHoUCGddlSQHMSRW+wjfQPjuEOitzGOksa3Lv2nozk0KheipislvFNqGG12DmWYCz5paOFbVs0VDSCuJI2LCmtyAeXR31rilW1sLCS2WzRzJXypVvTA/BLScKkYwusMkZizTMbB4GlyPjOY6z8UXP24nQoKd7hO0hN1wLRF2ln4dSC2y+AF/xKnqoUtTAuzxa0zp8lSYRWQTlNMz+ka1qhjuE0z+eMnQP13LROBnDCKGiPmLUYxcgwDx1rF0f02yB3u/g2rKng0t6vMjRfsrq6Fwia0DQXV/3KAnV/fMCzWNmbfeQtyst34lMAsJTQ5/ue0RpyVz3ROZRo3nTghjgbog+T0fwJ9xtM7Ww2WCHo4o2wObaSxznt20bJeCIbfakLcVN7FdRtVdocierKOTIjfoZoir1VNNn00=
youremail@gmail.com

登录github:https://github.com/
右上角你的头像
在这里插入图片描述
选择settings

点击new SHH key
在这里插入图片描述
保存即可。

2设置git账户

和上面的步骤一样即可(记得id_rsa改个不一样的,我公司用的使用的是默认的id_rsa)。
在这里插入图片描述

3.设置双ssh

设置git.config文件(没有新建即可),文件内容如下

Host github.com
HostName github.com
User youremail@gmail.com
PreferredAuthentications publickey
IdentityFile C:\Users\hynev\.ssh\id_rsa_github

Host yourotherhost.com
HostName yourotherhost.com
User yourotheremail@gmail.com
PreferredAuthentications publickey
IdentityFile C:\Users\hynev\.ssh\id_rsa

host,hostName填域名
user填email
identityfile填公钥文件名(不含.pub)

执行命令

ssh-add id_rsa_github
ssh-add id_rsa_gitee

注:如果出现Could not open a connection to your authentication agent,那么先执行

eval $(ssh-agent)

再执行ssh-add命令即可。

4.测试

ssh -T git@github.com

如果显示

Hi youremail@gmail.com! You’ve successfully authenticated, but GitHub
does not provide shell access.

代表设置成功。


题外话:虽然设置成功,idea也没问题,但是github通过ssh无法clone项目,目前不知道什么问题,只能通过https,pull和push没有影响。先用着,回头再看,如果你知道的话,希望可以帮忙解惑,谢谢

$ git clone git@github.com:youremail@gmail.com/project.git Cloning into
‘project’… git@github.com: Permission denied (publickey). fatal:
Could not read from remote repository.

Please make sure you have the correct access rights and the repository
exists.
$ git clone https://github.com/youremail@gmail.com/project.git
Cloning into ‘uniioe’…
remote: Enumerating objects: 933, done.
remote: Counting objects: 100% (933/933), done.

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值