ssh免密码配置

1.首先确保你的虚拟机能连上网络,首先我选择ping百度确定虚拟机是否有网络,如下代码是网络畅通的情况,如果不能ping通百度,请看我另一篇关于网卡的配置。

[root@master ~]# ping www.baidu.com
PING www.a.shifen.com (119.75.213.61) 56(84) bytes of data.
64 bytes from 119.75.213.61: icmp_seq=1 ttl=128 time=36.7 ms
64 bytes from 119.75.213.61: icmp_seq=2 ttl=128 time=37.2 ms
64 bytes from 119.75.213.61: icmp_seq=3 ttl=128 time=36.9 ms
64 bytes from 119.75.213.61: icmp_seq=4 ttl=128 time=36.7 ms
64 bytes from 119.75.213.61: icmp_seq=5 ttl=128 time=36.9 ms

2.在root账户下我们先关闭防火墙:

[root@master ~]# service iptables stop

或者选择以下命令永久关闭防火墙:

[root@master ~]# chkconfig iptables off    

3.(root用户执行)安装ssh协议,执行下面两条命令:

[root@master ~]# yum install ssh
[root@master ~]# yum install rsyuc

4.(hadoop用户执行)生成SSH公钥:
首先切换到hadoop用户,在主节点执行“ssh-keygen -t rsa”,遇到提示一直回车即可,最后会显示图像就是公钥指纹加密,然后再执行“ssh-copy-id -i ~/.ssh/id_rsa.pub hadoop@master”就会将公钥发至本机且在本地生成authorized_keys文件,第一次登陆需要输入Hadoop密码:

[root@master ~]# su - hadoop
[hadoop@master ~]$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/hadoop/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/hadoop/.ssh/id_rsa.
Your public key has been saved in /home/hadoop/.ssh/id_rsa.pub.
The key fingerprint is:
a8:58:8d:0e:93:b4:99:11:6a:f3:b1:15:cc:2f:16:b9 hadoop@master
The key's randomart image is:
+--[ RSA 2048]----+
|  . o..          |
| . . =.          |
|.oo. .+          |
|..o*+E o         |
|  Bo+ + S        |
|   * .           |
|  . o            |
|                 |
|                 |
+-----------------+
[hadoop@master ~]$ cd ~/.ssh/
[hadoop@master .ssh]$ ls
id_rsa  id_rsa.pub
[hadoop@master .ssh]$ ssh-copy-id -i ~/.ssh/id_rsa.pub hadoop@master
The authenticity of host 'master (192.168.137.200)' can't be established.
RSA key fingerprint is 2e:0f:f4:40:3c:96:ea:e4:0e:11:bb:25:60:7f:4b:af.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'master,192.168.137.200' (RSA) to the list of known hosts.
hadoop@master's password: 
Permission denied, please try again.
hadoop@master's password: 
Now try logging into the machine, with "ssh 'hadoop@master'", and check in:

  .ssh/authorized_keys

to make sure we haven't added extra keys that you weren't expecting.

5.验证是否成功,如下就是成功的:

[hadoop@master .ssh]$ ssh hadoop@master
Last login: Sat Oct 13 23:12:48 2018 from 192.168.137.1
[hadoop@master ~]$ 

6.如果没有成功,建议更改权限:

[hadoop@master ~]$ chmod 700 /home/hadoop/.ssh/
[hadoop@master ~]$ chmod 644 /home/hadoop/.ssh/authorized_keys 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值