需求
正常情况下,使用私钥ssh服务器的话,默认是使用.ssh/id_rsa这个文件存放私钥。如果是多台服务器的话就不能正常使用了。所以一个多私钥的需求就产生了。
开始施工
生成公钥与私钥
ssh-keygen,在.ssh/下生成名为’ali_rsa’的公钥与私钥,其中ssh使用的账号与地址为’i@imzcc.com'SHELL1ssh-keygen -t rsa -f .ssh/ali_rsa -C "i@imzcc.com"ssh-keygen -t rsa -f .ssh/ali_rsa -C "i@imzcc.com"
在.ssh/目录下 新建config文件
PLAINTEXT1# user@example1.com 2Host example1.com 3 User root 4 HostName domain1.com 5 PreferredAuthentications publickey 6 IdentityFile .ssh/host1_rsa 7 8# user@example2.com 9Host example2.com 10 User root 11 HostName domain2.com 12 PreferredAuthentications publickey 13 IdentityFile .ssh/host2_rsa# user@example1.com Host example1.com User root HostName domain1.com PreferredAuthentications publickey IdentityFile .ssh/host1_rsa # user@example2.com Host example2.com User root HostName domain2.com PreferredAuthentications publickey IdentityFile .ssh/host2_rsa
测试
ssh user@example1.com不用输入密码即可登入。
如果无法登录则需要修改ssh服务端配置文件
修改ssh服务
修改ssh服务端配置文件
SHELL1vim /etc/ssh/sshd_configvim /etc/ssh/sshd_config
允许root用户登录,增加以下配置
TEXT1PermitRootLogin yesPermitRootLogin yes
允许私钥登录,增加以下两行
TEXT1RSAAuthentication yes 2PubkeyAuthentication yesRSAAuthentication yes PubkeyAuthentication yes
重启服务
SHELL1/etc/initd.d/ssh restart/etc/initd.d/ssh restart
部分方案来自这里