Chinaunix首页 | 论坛 | 博客
  • 博客访问: 417781
  • 博文数量: 122
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 688
  • 用 户 组: 普通用户
  • 注册时间: 2013-09-04 12:30
文章分类

全部博文(122)

文章存档

2017年(5)

2016年(4)

2015年(56)

2014年(41)

2013年(16)

我的朋友

分类: LINUX

2015-05-28 18:38:35

ssh 无密码登陆
一、公钥和私钥
在构建无密码登陆之前说明:ssh的密码是加密的,分为公钥和私钥
公钥是给别人的,私钥是自己留着的 
公钥加密的东西,用私钥解 
私钥加密的东西,用公钥解  

如果B想无密码登陆到A。

B 产生自己本机的公钥和私鈅,并且把公钥给A,当B登陆到A时,B上的私鈅会解读A上面的公钥。

二、B产生公、私鈅
在B上运行如下的命令:
ssh-keygen -t rsa     #### -t 表示加密的方式  rsa
Generating public/private dsa key pair.
Enter file in which to save the key (/root/.ssh/id_dsa): 
Enter passphrase (empty for no passphrase): (直接回车)
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_dsa.
Your public key has been saved in /root/.ssh/id_dsa.pub.
The key fingerprint is:
82:0c:91:f4:61:d0:03:52:e0:86:6a:66:77:f7:d0:40 userB@nodeB

2、在B的主目录下:.ssh/产生2个文件id_rsa id_rsa.pub 其中:id_rsa.pub就是公钥。

3、在B上运行如下的命令
$ ssh-copy-id -i  userA@nodeA 
就会自动把B上的文件:~/.ssh/id_rsa.pub 文件拷贝到nodeA的~/.ssh/下,并且命名为authorized_keys. ***

4、在A上运行如下的命令
$cd /root/.ssh/
$cat id_rsa.pub >>authorized_keys


这样B即可利用自己的公钥来访问A,实现无密码登陆到A。
阅读(822) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~