使用expect省去輸入ssh密碼之苦

將ssh登錄使用的Identity放到當前目錄下,注意把權限改成600,然後執行下面的腳本,就可以在遠程服務器上執行命令,而不用每次都輸入密碼。
 
#!/usr/bin/env expect
 
if {$argc < 2} {   #}\space{
  send_user "usage: $argv0 command\n"
  exit
}
 
set timeout 10
spawn ssh -i Identity -l root -p 22 192.168.10.10 $argv
expect "Enter passphrase for key*"
send "my password\n"
expect eof
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章