先決條件
3 臺 CentOS 7
HOSTNAME | IP | ROLE |
---|---|---|
server1 | 10.8.26.197 | Master |
server2 | 10.8.26.196 | Slave1 |
server3 | 10.8.26.195 | Slave2 |
步驟
1. 用 root 用戶登錄。每臺服務器都生成公鑰,再合并到 authorized_keys。
2. CentOS 默認沒有啟動 ssh 無密登錄,去掉 /etc/ssh/sshd_config
其中 2 行的注釋,每臺服務器都要設置。
1
2
|
RSAAuthentication yes PubkeyAuthentication yes |
3. 每臺服務器下都輸入命令 ssh-keygen -t rsa
,生成 key,一律不輸入密碼,直接回車,/root
就會生成 .ssh
文件夾。
4. 在 Master 服務器下,合并公鑰到 authorized_keys
文件,進入 /root/.ssh
目錄,通過 SSH 命令合并.
1
2
3
|
# cat id_rsa.pub>> authorized_keys # ssh [email protected] cat ~/.ssh/id_rsa.pub>> authorized_keys # ssh [email protected] cat ~/.ssh/id_rsa.pub>> authorized_keys |
5. 把 Master 服務器的 authorized_keys
、known_hosts
復制到 Slave 服務器的 `/root/.ssh
目錄
1
2
3
4
|
# scp authorized_keys root@server2:/root/.ssh/ # scp authorized_keys root@server3:/root/.ssh/ # scp known_hosts root@server2:/root/.ssh/ # scp known_hosts root@server3:/root/.ssh/ |
6. 完成,ssh [email protected]
、ssh [email protected]
就不需要輸入密碼了。
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。
原文鏈接:https://segmentfault.com/a/1190000008615560