作者:馬帥琦
歸檔:day38
時間:2019/4/23
1.ssh-keygen非交互式創(chuàng)建秘鑰對:
具體命令:ssh-keygen -f ~/.ssh/id_rsa -P '' -q
參數(shù)講解:
ssh-keygen:密鑰對創(chuàng)建工具 [-P old_passphrase] 密碼 [-f output_keyfile] 輸出的秘鑰文件 [-q] 不輸出信息 [-t dsa ] 指定秘鑰類型速勇。
2.ssh-copy-id不需要提示yes/no分發(fā)秘鑰
具體命令:ssh-copy-id -f -i ~/.ssh/id_rsa.pub -o StrictHostKeyChecking=no 172.16.1.8
參數(shù)講解:
ssh-copy-id -f -i ~/.ssh/id_rsa.pub -o StrictHostKeyChecking=no root172.16.1.8
ssh-copy-id [-f] [-i [identity_file]] [-p port] [[-o <ssh -o options>] ...] [user@]hostname
說明:
-f: force mode 強(qiáng)制
[-i [identity_file]] 指定秘鑰文件
[[-o <ssh -o options>] ...] 指定ssh參數(shù)選項逞带。
3.sshpass工具:指定密碼非人工交互分發(fā)秘鑰
sshpass -p123456 ssh-copy-id -f -i ~/.ssh/id_rsa.pub "-o StrictHostKeyChecking=no" 172.16.1.7
[root@web02 ~]# sshpass -help
Usage: sshpass [-f|-d|-p|-e] [-hV] command parameters
sshpass -p123456 ssh-copy-id -f -i ~/.ssh/id_rsa.pub "-o StrictHostKeyChecking=no" 172.16.1.7
sshpass [-f|-d|-p|-e] [-hV] command parameters
參數(shù)講解:
-p password Provide password as argument (security unwise) #指定用戶密碼操作
4.一鍵配置實踐
把web02作為分發(fā)服務(wù)器:
web02(8)-->m01(61)
web02(8)-->web01(7)
ssh-keygen -f ~/.ssh/id_rsa -P '' -q
ssh-copy-id -f -i ~/.ssh/id_rsa.pub "-o StrictHostKeyChecking=no" 172.16.1.7
sshpass -p123456 ssh-copy-id -f -i ~/.ssh/id_rsa.pub "-o StrictHostKeyChecking=no" 172.16.1.7
#!/bin/bash
#yum install sshpass -y
ssh-keygen -f ~/.ssh/id_rsa -P '' -q
for ip in 7 61
do
sshpass -p123456 ssh-copy-id -f -i ~/.ssh/id_rsa.pub "-o StrictHostKeyChecking=no" 172.16.1.$ip
done
#test
ssh 172.16.1.7 "ifconfig eth0"
ssh 172.16.1.61 "ifconfig eth0"