我試圖通過小型bash腳本執行expect命令以使用密鑰身份驗證方法登錄到服務器。我的腳本如下:預計不會在我的Bash腳本中工作
#!/bin/bash
HOST=$1
/usr/bin/expect -c "
spawn ssh -i /root/.ssh/id_rsa [email protected]$HOST
expect -exact "Enter passphrase for key '/root/.ssh/id_rsa': " ;
send "PASSPHRASE\n" ;
interact
"
輸出,錯誤是:
spawn ssh -i /root/.ssh/id_rsa [email protected]
couldn't read file "passphrase": no such file or directory
你能幫助糾正呢?
有人可以幫忙嗎? – John 2014-09-27 17:49:58
考慮使用'ssh-agent'而不是'expect'。 – jordanm 2014-09-27 18:26:46
@jordanm謝謝。你能告訴我爲什麼你在這裏建議使用ssh-agent?以及使用它的目的是什麼? – John 2014-09-28 07:02:29