登陆ssh不需要使用密码

来源:互联网 发布:javascript box2d 编辑:程序博客网 时间:2024/06/02 07:31
每次登陆ssh都需要输入用户名和密码,我想作一个双机的互备。考虑密码隔断时间都需要修改,那我的备份程序也需要修改。因此就想使用不需要密码用ssh登陆机器,这样我就可以使用rsync,scp,rexec等命令来做的远程备份了。方法如下:假设A,B两服务器,现在需要在A机上用root登陆B机,而不需要输入密码,那我们可按照下面的步骤来做:1)在A机上生成钥匙对A# ssh-keygen -t rsaGenerating public/private rsa key pair.Enter file in which to save the key (/root/.ssh/id_rsa):Enter passphrase (empty for no passphrase):Enter same passphrase again:Your identification has been saved in /root/.ssh/id_rsa.Your public key has been saved in /root/.ssh/id_rsa.pub.The key fingerprint is:f6:61:a8:27:35:cf:4c:6d:13:22:70:cf:4c:c8:a0:23 mlsx@mlsx这样,会生成id_rsa,和id_rsa.pub,其中id_rsa是密钥,id_rsa.pub是公钥。2)把在A机生成的id_rsa.pub拷贝到B机上。A# scp id_rsa.pub root@B:/tmp3)用root帐号登陆B机,进入其主目录,创建authorized_keys文件,并设置好权限B# cd ~/.ssh#cat /tmp/id_rsa.pub >>authorized_keys#chmod 400 authorized_keys4)测试在A机上转到root帐号,尝试登录B机。看看是不是不要密码.5)authorized_keys文件的权限很重要,如果设置为777,那么登录的时候,还是需要提供密码的。本方法在Fedora Core 2 和RedFlag Desktop 4.1上测试通过。有什么问题,欢迎交流!
原创粉丝点击