主機master ,slaver1,slaver2javascript
一、每臺主機都執行java
ssh-keygen -t rsa
而後一直回車ruby
二、操做master。master生成公鑰 放入authorized_keys
文件中,而後發送個slave1,記住只發送給slave1不要發送給slaver2ssh
cd ~/.sshspa
cat id_rsa.pub
code
scp ~/.ssh/authorized_keys slave1:~/.ssh/
三、操做slaver1。slaver1生成公鑰 放入authorized_keys
文件中,而後發送個slave1,記住只發送給slave1不要發送給master(至關於往authorized_keys添加三臺主機的公鑰)regexp
cd ~/.sship
cat id_rsa.pub
ast
scp ~/.ssh/authorized_keys slave2:~/.ssh/
四、操做slaver2。slaver2生成公鑰 放入authorized_keys
文件中,而後發送個slave1和masterclass
cd ~/.ssh
cat id_rsa.pub
scp ~/.ssh/authorized_keys slave1:~/.ssh/
scp ~/.ssh/authorized_keys slave2:~/.ssh/
注意:必定要按上面的步驟一步一步來,若是不當心弄錯了,刪掉每臺機器的.ssh文件而後從新執行。
參考:https://www.jianshu.com/p/991b39c48b0f