Chinaunix首页 | 论坛 | 博客
  • 博客访问: 226533
  • 博文数量: 66
  • 博客积分: 2510
  • 博客等级: 少校
  • 技术积分: 700
  • 用 户 组: 普通用户
  • 注册时间: 2009-07-27 22:10
个人简介

闲时会写写程序的非技术人员。

文章分类

全部博文(66)

文章存档

2022年(1)

2018年(11)

2011年(1)

2010年(36)

2009年(17)

我的朋友

分类: LINUX

2010-07-13 16:55:40

转自:http://blog.wgzhao.com/2005/05/23/login-without-password-using-ssh.html#more-94


每次登陆ssh都需要输入用户名和密码,我想作一个双机的互备。考虑密码隔断时间都需要修改,那我的备份程序也需要修改。因此就想使用不需要密码用 ssh登陆机器,这样我就可以使用rsync,scp,rexec等命令来做的远程备份了。

方法如下:
假设A,B两服务器,现在需要在A机上用root登陆B机,而不需要输入密码,那我们可按照下面的步骤来做:
1)在A机上生成钥匙对

A# ssh-keygen -t rsa
Generating 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:/tmp

3)用root帐号登陆B机,进入其主目录,创建authorized_keys文件,并设置好权限

B# cd ~/.ssh
#cat /tmp/id_rsa.pub >>authorized_keys
#chmod 400 authorized_keys

4)测试
在A机上转到root帐号,尝试登录B机。看看是不是不要密码.

5)authorized_keys文件的权限很重要,如果设置为777,那么登录的时候,还是需要提供密码的。

阅读(634) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~