ssh-keygen非交互式創(chuàng)建秘鑰對

作者:馬帥琦
歸檔:day38
時(shí)間: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ù)選項(xiàng)。

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.一鍵配置實(shí)踐

把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"
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容