Linux 下配置 hosts 并设置免密登录

Linux 下配置 hosts 并设置免密登录

作者:Grey

原文地址:

博客园:Linux 下配置 hosts 并设置免密登录

CSDN:Linux 下配置 hosts 并设置免密登录

说明

实现 Linux 下(基于 CentOS 7)两个节点之间进行免密登录。

环境

操作系统:CentOS 7

下载地址

安装说明

需要准备两个节点,一个是 master 节点,另一个是 slave 节点。

其中 master 节点的 IP:192.168.100.130

slave 节点的 IP:192.168.100.131

操作步骤

首先,配置 hosts,在 master 节点上,执行如下命令设置 hostname

hostnamectl set-hostname master

然后执行

vi /etc/hosts

添加如下两行

192.168.100.130 master
192.168.100.131 slave

在 slave 节点上,执行如下命令设置 hostname

hostnamectl set-hostname slave

然后执行

vi /etc/hosts

添加如下两行

192.168.100.130 master
192.168.100.131 slave

在 master 下执行

ssh-keygen -t rsa

一路回车,

然后在 master 上执行

ssh-copy-id master

输入 yes,然后回车,接着输入 root 密码,然后会得到如下日志

Number of key(s) added: 1

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

验证一下,在 master 节点执行

ssh master

可以免密登录

[root@master kafka]# ssh master
Last login: Mon Oct 17 21:06:18 2022 from 192.168.100.1

在 slave 下执行

ssh-keygen -t rsa

一路回车,

然后在 slave 上执行

ssh-copy-id slave

输入 yes,然后回车,接着输入 root 密码,然后会得到如下日志

Number of key(s) added: 1

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

验证一下,在 slave 节点执行

ssh slave

可以免密登录

[root@master kafka]# ssh slave
Last login: Mon Oct 17 21:06:18 2022 from 192.168.100.1

在 slave 上执行

ssh-copy-id master

输入 yes,然后回车,接着输入 master 节点的 root 密码,然后会得到如下日志

Number of key(s) added: 1

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

测试一下,在 slave 下执行

ssh master

免密登录成功

[root@slave ~]# ssh master
Last login: Mon Oct 17 21:51:12 2022 from master
[root@master ~]# 

同理,在 master 上执行

ssh-copy-id slave

输入 yes,然后回车,接着输入 slave 节点的 root 密码,然后会得到如下日志

Number of key(s) added: 1

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

测试一下,在 master 下执行

ssh slave

免密登录成功

[root@master kafka]# ssh slave
Last login: Mon Oct 17 21:58:29 2022 from slave
[root@slave ~]# 

这样就实现了两个节点的免密登录。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

GreyZeng

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值