生成秘钥的步骤:
-
ssh-keygen -t rsa -C "xxxx@qq.com"
添加秘钥
在不同的域中添加相同的秘钥是没有问题的,比如 github.com / code.aliyun.com
如果我想不同的域用不同的账号,或者同一个域有多个账号怎么办?
以上情况就需要生成多个秘钥
ssh-keygen -t rsa -C "xxxx@qq.com"
回车,注意文件名需要修改,比如: id_rsa_qq
另外两项直接回车ssh-keygen -t rsa -C "xxxx@yahoo.com"
回车,注意文件名需要修改,比如: id_rsa_yahoo
另外两项直接回车
此刻文件生成好了,然后是配置
- ssh-add ~/.ssh/id_rsa_qq
ssh-add ~/.ssh/id_rsa_yahoo
vim config 添加以下内容:
- # 配置code.aliyun.com
- Host code.aliyun.com
- HostName code.aliyun.com
- IdentityFile /root/.ssh/id_rsa_yahoo
- PreferredAuthentications publickey
- User xxxx@yaoo.com
-
- # 配置code.aliyun.com
- Host code.aliyun.com
- HostName code.aliyun.com
- IdentityFile /root/.ssh/id_rsa_qq
- PreferredAuthentications publickey
- User xxxx@qq.com
-
- # 配置github
- Host github.com
- HostName github.com
- IdentityFile /root/.ssh/id_rsa_github
- PreferredAuthentications publickey
- User xxxx@gmail.com
注意: 同一个域名的只有第一个有效