姜鹏辉的个人博客 GreyNius

【Linux】生成多份SSH密钥的方法

2021-06-29

解决方案

ssh-keygen -t rsa -C "jiangph1001@qq.com"  -f ~/.ssh/id_rsa_2016
ssh-keygen -t rsa -C "jiangph1001@foxmail.com" -f ~/.ssh/id_rsa_1001

执行完以后,会在.ssh目录下生成两对公私钥

$ ls
id_rsa_1001     id_rsa_1001.pub id_rsa_2016     id_rsa_2016.pub known_hosts

然后使用ssh-add添加密钥到ssh-agent中

ssh-add ~/.ssh/id_rsa_2016
ssh-add ~/.ssh/id_rsa_1001

.ssh目录下新建config文件

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

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

参考:


Similar Posts

Comments