首先,在新增私钥的时候,通过指定不同的文件名来生成不同的私钥文件
ssh-keygen -t rsa -f ~/.ssh/id_rsa.work -C "your email"
ssh-keygen -t rsa -f ~/.ssh/id_rsa.gitee -C "your email"
新增ssh的配置文件,并修改权限
touch ~/.ssh/config
chmod 600 ~/.ssh/config
# config内容
Host *.workdomain.com
IdentityFile ~/.ssh/id_rsa.work
User lee
Host gitee.com
IdentityFile ~/.ssh/id_rsa.gitee
User git
这样在登陆的时候,ssh会根据登陆不同的域来读取相应的私钥文件,测试
ssh -T git@gitee.com
#Hi xxx! You've successfully authenticated, but GITEE.COM does not provide shell access.
#出现这样的提示语表示配置正确
文章来源于:https://blog.csdn.net/chaihuasong/article/details/37886139