Chinaunix首页 | 论坛 | 博客
  • 博客访问: 5086332
  • 博文数量: 553
  • 博客积分: 13864
  • 博客等级: 上将
  • 技术积分: 11041
  • 用 户 组: 普通用户
  • 注册时间: 2011-11-28 21:25
个人简介

个人Blog: hhktony.com

文章分类

全部博文(553)

文章存档

2015年(1)

2014年(2)

2013年(12)

2012年(384)

2011年(154)

分类: LINUX

2011-12-24 00:35:39


一,在test1主机里的用户


运行 ssh-keygen -t rsa
结果如下
Generating public/private rsa key pair.
Enter file in which to save the key (/home/bob/.ssh/id_rsa):
Created directory '/home/bob/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/bob/.ssh/id_rsa.
Your public key has been saved in /home/bob/.ssh/id_rsa.pub.
The key fingerprint is:
b7:99:2b:88:0b:02:1d:a0:d5:68:bd:bb:00:86:d2:d1 bob@
会在bob用户目录~/.ssh /产生两个文件,id_rsa,id_rsa.pub
其中id_rsa 为私钥,id_rsa.pub为公钥
二,把id_rsa.pub 文件拷贝到test2主机的用户目录下,如root目录下

cat id_rsa.pub >~/.ssh/authorized_keys
就可以了

这样test1主机的用户就可以通过ssh而不用密码登陆 test2主机

三、 现在我们把test1主机的内容copy到test2主机时就不需要提示密码了。

scp /root/a.txt root@test2:/root/   不需要输入密码

如果要用其他用户去验证的话,那么在步骤二中我们就需要把公钥copy到对应用户的.ssh/authorized_keys即可 。

四 、通过上面三个步骤的实现 ,当我们写脚本来使用scp来copy文件时就很方便了
阅读(3012) | 评论(0) | 转发(2) |
给主人留下些什么吧!~~