Linux配置多臺機器SSH相互通訊信任
阿新 • • 發佈:2018-12-05
2臺機器分別執行ssh-keygen生成公鑰和金鑰
[[email protected] ~]# ssh-keygen
生成.ssh資料夾及id_rsa和id_rsa.pub
[[email protected] .ssh]# ll
total 16
-rw-------. 1 root root 1675 Dec 13 21:37 id_rsa
-rw-r--r--. 1 root root 396 Dec 13 21:37 id_rsa.pub
選取第一臺,生成authorized_keys檔案
[[email protected] ~]# cd .ssh
[ [email protected] .ssh]# cat ./id_rsa.pub >> ./authorized_keys
將另一臺id_rsa.pub內容,手動copy到第一臺的authorized_keys檔案
[[email protected] .ssh]# more id_rsa.pub
拷貝至`authorized_keys`檔案(注意copy時,最好先放到記事本中,將回車去掉,成為一行)
設定每臺機器的許可權
[[email protected] ~]# chmod 700 -R ~/.ssh
[[email protected] ~]# chmod 600 ~/.ssh/authorized_keys
將第一臺的authorized_keys scp 給hadoop-02(第一次傳輸,需要輸入密碼)
[[email protected] ~]# scp authorized_keys [email protected]:/root/.ssh
配置/etc/hosts(兩臺機器都要配置)
[[email protected] ~]# vi /etc/hosts 將兩臺機器的IP和機器名都寫入 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 192.168.137.130 hadoop-01 192.168.137.131 hadoop-02
驗證(每臺機器上執行下面的命令,只輸入yes,不輸入密碼,則這兩臺互相通訊了)
[[email protected] ~]# ssh [email protected] date
[[email protected] ~]# ssh [email protected]01 date