MENU

git同时设置多个ssh-key

July 5, 2022 • linux相关

1. 生成 ssh-key

gitee 平台一套:

$ ssh-keygen -t rsa -C '[email protected]' -f ~/.ssh/gitee_id_rsa

github 平台一套:

$ ssh-keygen -t rsa -C '[email protected]' -f ~/.ssh/github_id_rsa

如果是 ED25519,则如:

ssh-keygen -t ed25519 -C "<comment>" -f ~/.ssh/xxx_id_ed25519

2. 设置 git 配置 ~/.ssh/config

# gitee
Host gitee.com
HostName gitee.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/gitee_id_rsa

# github
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/github_id_rsa

3. 用 ssh 命令分别测试

$ ssh -T [email protected]
$ ssh -T [email protected]