有不少人拥有多个github账号,比如个人账号,用户开源的账号。那如何在同一台电脑上管理多个github账号呢?

1. 使用https方式

git clone https://[email protected]/duanhjlt/blog.git
git clone https://[email protected]/duan0120/xvm.git

2. 使用ssh方式

2.1 创建ssh key

ssh-keygen -t ed25519 -C "[email protected]" -f ~/.ssh/id_ed25519_github1
ssh-keygen -t ed25519 -C "[email protected]" -f ~/.ssh/id_ed25519_github2

2.2 将ssh公钥添加到对应的github账号

2.3 设置ssh

2.3.1 设置配置文件

# ~/.ssh/config

Host github.com
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_ed25519_github2
    
Host github1.com
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_ed25519_github1

2.3.2 清除当前ssh代理中的密钥

ssh-add -D

2.3.3 添加需要的密钥

ssh-add ~/.ssh/id_ed25519_github1
ssh-add ~/.ssh/id_ed25519_github2

2.3.4 验证加载的密钥

ssh-add -l

2.3.5 测试链接

2.4 clone 代码

git clone [email protected]:duanhjlt/blog.git
git clone [email protected]:duan0120/xvm.git