同机多Github账号配置多个SSH

1,185 阅读1分钟

前言

有一些情况,我们需要在同一个机子配置多个github的ssh链接;

步骤

生成多个SSH

ssh-keygen -t rsa -C "emailxxxx"

需要注意的就是生成的密钥名字不能一样,

接着就是把对应的公钥配置到你的github账号;

Github配置路径: avatar(dropdown)->settings->SSH and GPG keys

编辑ssh的配置文件

在系统当前用户家目录编辑/创建一个SSH配置文件 (~/.ssh/config)

Host github.com-crper
    HostName github.com
    user crper
    IdentityFile "~/.ssh/id_rsa"
    IdentitiesOnly yes


Host github.com-ones
    HostName github.com
    user linqunhe
    IdentityFile "~/.ssh/id_rsa_ones"
    IdentitiesOnly yes

添加代理

ssh-add — adds private key identities to the authentication agent
# 意思就是可以把多个私钥添加到验证代理统一维护

image.png

验证

校验远程服务器

image.png

拉取代码

唯一有区域的就是拉取代码要注意远程域名为配置的域!!比如 image.png

总结

配置起来不麻烦,克隆维护这些也还好;

当然,若是只有两个账号,又很懒的.

可以考虑一个用Github Desktop来管理,非常傻瓜化!