A B 两台服务器,A为应用服务器,B为远程备份服务器
1.备份A原有密钥与公钥
# cd /root/.ssh/
# ls
authorized_keys id_rsa id_rsa.pub known_hosts
# mv authorized_keys authorized_keys_bak
# mv id_rsa id_rsa_bak
# mv id_rsa.pub id_rsa.pub_bak
# mv known_hosts known_hosts_bak
2.在A机器上生成新的密钥对
# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): /root/.ssh/id_rsa
......回车
3.把在A机生成的id_rsa.pub拷贝到B机上,假设拷贝到B机的临时目录下
# scp /root/.ssh/id_rsa.pub root@xxx.xxx.xxx.xxx:/tmp
4.用root帐号登陆B机,进入其主目录
# ssh root@1xxx.xxx.xxx.xxx
# cd /root/.ssh
5.检查authorized_keys 是否已存在,存在则不需要再次创建
如不存在:
# touch authorized_keys
# chmod 600 /root/.ssh/authorized_keys
6.上面生成的公钥id_rsa.pub追加到authorized_keys文件中
# cat /tmp/id_rsa.pub >>authorized_keys
7.删除B服务器的id_rsa.pub,避免与下一台服务器的公钥冲突
# rm -f /tmp/id_rsa.pub
8.测试是否连通
注:方法皆源于博客文章,根据自己实际使用测试归纳总结得到。