2011-11-03 92 views
0

我這樣理解所有使用ssh的安全風險,但我目前需要的是幾行(bash)shell腳本能夠登錄到target服務器,做一個Foo命令,並回到源主機,是這樣的:非交互式ssh到服務器,但交互式

while true 
do 
    ssh target foo # Here I get the prompt for a password which 
        # I would like to give non-interactively 
    sleep 1 
done 

不想使用SSH密鑰的身份驗證,因爲我真正需要的是模擬1次(左右)交互式登錄過程(但不是交互式!)。

回答

2

您需要使用expect來編寫腳本,例如perl

編輯:您也可以嘗試直接在bash腳本expect

0

您必須編輯SSH服務器以允許僅基於密鑰而不是密碼進行登錄。

試試看看this可以幫到你。

當然,如果你不能修改服務器的配置,你需要檢查的交互,而不是其他的解決方案

0

sshpass旨在提供一個密碼以編程SSH,。所以你可以用例如ssh target foo代替。 sshpass -f passwordfile ssh target foo