SSH无密登录配置

  1. 配置ssh
    (1)基本语法
    ssh另一台电脑的ip地址
    (2)ssh连接时出现Host key verification failed的解决方法
[hadoop@master opt] $ ssh 192.168.1.103
The authenticity of host '192.168.1.103 (192.168.1.103)' can't be established.
RSA key fingerprint is cf:1e:de:d7:d0:4c:2d:98:60:b4:fd:ae:b1:2d:ad:06.
Are you sure you want to continue connecting (yes/no)?
Host key verification failed.

(3)解决方案如下:直接输入yes
2. 无密钥配置
(1)免密登录原理,如图2-40所示
在这里插入图片描述

图2-40 免密登陆原理
(2)生成公钥和私钥:

[hadoop@master.ssh]$ ssh-keygen -t rsa

然后敲(三个回车),就会生成两个文件id_rsa(私钥)、id_rsa.pub(公钥)
(3)将公钥拷贝到要免密登录的目标机器上

[hadoop@master.ssh]$ ssh-copy-id hadoop102
[hadoop@master.ssh]$ ssh-copy-id hadoop103
[hadoop@master.ssh]$ ssh-copy-id hadoop104

注意:
还需要在master上采用root账号,配置一下无密登录到master、slave1、slave2;
还需要在slave1上采用hadoop账号配置一下无密登录到master、slave1、slave2服务器上。
3. .ssh文件夹下(~/.ssh)的文件功能解释
表2-4

known_hosts记录ssh访问过计算机的公钥(public key)
d_rsa生成的私钥
id_rsa.pub生成的公钥
authorized_keys存放授权过得无密登录服务器公钥

以下为具体操作截图:
生成公钥和私钥

[hadoop@master hadoop]$ 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:
SHA256:snqLDZ8bF00TDLq3JBbkNWR/op2anBinh4CPkvyCTak hadoop@master
The key's randomart image is:
+---[RSA 2048]----+
|      ..*o.      |
|     o + o..     |
|      +   = .    |
|   .   o = =     |
|  ... * S +      |
|..oo o & *       |
|+=. o * O        |
|Eoo  *.=         |
|  ..o.*o         |
+----[SHA256]-----+

将公钥拷贝到要免密登录的目标机器上

[hadoop@master hadoop]$ ssh-copy-id slave1
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/hadoop/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
hadoop@slave1's password:

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'slave1'"
and check to make sure that only the key(s) you wanted were added.

[hadoop@master hadoop]$ ssh-copy-id slave2
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/hadoop/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
hadoop@slave2's password:

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'slave2'"
and check to make sure that only the key(s) you wanted were added.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值