Loading

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 ~]# 

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

posted @ 2022-10-17 22:04  Grey Zeng  阅读(925)  评论(0编辑  收藏  举报