1. 程式人生 > >mac 指令碼ssh自動密碼登入伺服器,非公鑰

mac 指令碼ssh自動密碼登入伺服器,非公鑰

安裝工具

brew install expect
brew install spawn-fcgi

登入指令碼, 替換ip與密碼

#!/usr/bin/expect
set user root  
set ipaddress 120.76.xx.xx
set passwd xxx
set timeout 30

spawn ssh $user@$ipaddress
expect {
    "*password:" { send "$passwd\r" }
    "yes/no" { send "yes\r";exp_continue }
}
interact

執行登入,【不是bash,sh】

expect  login.sh
/usr/bin/expect login.sh