Linux 下配置 hosts 并设置免密登录 - Grey Zeng
source link: https://www.cnblogs.com/greyzeng/p/16800904.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Linux 下配置 hosts 并设置免密登录
作者:Grey
原文地址:
说明#
实现 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 ~]#
这样就实现了两个节点的免密登录。
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK