需求案例:
1、由于企业要求使用公司邮箱重新注册新的GitHub帐号开发美国企业的项目,之前在本机上配置 GitHub 帐号使用的ssh-key
不能使用到 GitHub其他帐号上,否则报错Key is already in use
,而之前的 GitHub 帐号还需要维护其他项目不能删掉 ssh-key,于是就需要GitHub多账号开发不同项目需求。
2、最开始是使用 GitHub 提供personal token
登录方式(github不再支持密码验证,通过设置Settings / Developer settings / Personal access tokens
获取 token),设置不同项目的remote origin
为https://{ { token值 }}@github.com/xxx/项目名.git
,push 代码到GitHub上,一开始这个方式很好解决需求,但是有时候却总 push fail (总是超时,我“科学上网”还是这样)而且时间很长,但是 ssh-key 方式却不会速度还很快(有知道原因的同学请在评论区科普下…)。
1、GitHub 多账户 ssh-key 配置
比如,你有2个GitHub帐号: A和B, A 帐号的邮箱为[email protected],B 帐号的邮箱为[email protected] ,现在需要为2个帐号配置ssh-key。
1-使用 ssh-keyge 为A和B生成密钥对
# 密钥对生成在用户主目录下的.ssh文件夹,比如win系统
C:\Users\Administrator\.ssh
1、打开