使用 plink 在快取中自動儲存伺服器主機金鑰

使用 plink 在快取中自動儲存伺服器主機金鑰

我一直在嘗試使用 plink 發出命令來從外部伺服器檢索資訊。請注意,這些 plink 命令是從不需要使用者輸入的二進位檔案中運行的。是否有一個標誌允許我覆蓋此錯誤訊息並繼續程式輸出?

The server's host key is not cached in the registry. You
have no guarantee that the server is the computer you
think it is.
The server's rsa2 key fingerprint is:
ssh-rsa 2048 **:**:**:**:**:**:**:**:**:**:**:**:**:**:**:**
If you trust this host, enter "y" to add the key to
PuTTY's cache and carry on connecting.
If you want to carry on connecting just once, without
adding the key to the cache, enter "n".
If you do not trust this host, press Return to abandon the
connection.
Store key in cache? (y/n)

謝謝你!

答案1

嘗試在腳本前面加上:

echo y | plink -ssh root@REMOTE_IP_HERE "exit"

當您獲得時,這會將y角色通過管道傳送到stdinplink將密鑰儲存在快取中? (是/否)提示,允許所有進一步的plink命令通過而無需用戶輸入。該exit命令將在建立 SSH 會話後關閉它,從而允許plink執行以下命令。

下面是一個範例腳本,它將外部伺服器的 Unix 時間寫入本機檔案:

echo y | plink -ssh root@REMOTE_IP_HERE "exit"
plink -ssh root@REMOTE_IP_HERE "date -t" > remote_time.tmp

流水線參考:http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-4.html

答案2

接受的答案是“可以接受”,但不安全。最好的方法是指定 plink 的主機金鑰以防止任何中間人攻擊。

plink -hostkey aa:bb:cc... root@REMOTE_IP_HERE [...]

答案3

PuTTYplink.exe在安裝它們的主機上共享“可接受的伺服器密鑰”的相同快取。

所以如果你的場景是互動的(因此,當您按下「y」或「n」時,您的挫折感不會被聽到),解決方法是先嘗試與 PuTTY 連接。

執行此操作時:

  • 您將打開PuTTY並假裝啟動與伺服器的互動式 SSH 會話
  • 您將看到一個 Windows 對話框,其中顯示一個金鑰,詢問您是否要信任它
  • 您將檢查所提供的鑰匙,通往 MITM 的病房,然後按OK
  • 從今以後,plink.exe不會再費心去問你是否信任伺服器——它已經知道你信任了

答案4

auto_store_sshkey選項存在於克林克,這是貓咪,可以跳過儲存鍵提示。

klink -auto_store_sshkey -batch 192.211.158.256 -l user -pw password 

相關內容