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 master192.168.100.131 slave在 slave 節點上,執行如下命令設置 hostname
hostnamectl set-hostname slave然后執行
vi /etc/hosts添加如下兩行
192.168.100.130 master192.168.100.131 slave在 master 下執行
ssh-keygen -t rsa一路回車,
然后在 master 上執行
ssh-copy-id master輸入 yes,然后回車 , 接著輸入 root 密碼,然后會得到如下日志
Number of key(s) added: 1Now 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 masterLast 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: 1Now 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 slaveLast 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: 1Now 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 masterLast 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: 1Now 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【Linux 下配置 hosts 并設置免密登錄】免密登錄成功
[root@master kafka]# ssh slaveLast login: Mon Oct 17 21:58:29 2022 from slave[root@slave ~]#這樣就實現了兩個節點的免密登錄 。

    推薦閱讀