1. 程式人生 > 其它 >006免密登入

006免密登入

技術標籤:大資料大資料運維linux

1、原理

2.實現免密登入(node1免密登入node1,node2,node3,node2免密登入node1,node2,node3)

2.1 node1免密登入node1,node2,node3

登入node1

#生成金鑰對
ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa
#傳送公鑰至node2,node3
for i in {2..3}; do ssh node$i 'mkdir ~/.ssh';scp ~/.ssh/id_rsa.pub [email protected]$i:~/.ssh/id_rsa.pub.node1;done
#將公鑰內容複製到~/.ssh/authorized_keys
for i in {2..3}; do ssh node$i 'cat ~/.ssh/id_rsa.pub.node1 >> ~/.ssh/authorized_keys';done

cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

2.1 node2免密登入node1,node2,node3

登入node2

#生成金鑰對
ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa
#傳送公鑰至node2,node3
for i in {1,3}; do ssh node$i 'mkdir ~/.ssh';scp ~/.ssh/id_rsa.pub [email protected]$i:~/.ssh/id_rsa.pub.node2;done
#將公鑰內容複製到~/.ssh/authorized_keys
for i in {1,3}; do ssh node$i 'cat ~/.ssh/id_rsa.pub.node2 >> ~/.ssh/authorized_keys';done
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys