Linux 使用expect自动输入密码

#!/usr/bin/expect
#trap sigwinch spawned
trap {
 set rows [stty rows]
 set cols [stty columns]
 stty rows $rows columns $cols < $spawn_out(slave,name)
} WINCH

  
set ip "192.168.x.x"
set pwd "xxx"
set timeout 30

spawn ssh ubuntu@$ip
expect {
"*yes/no" {send "yes\r";exp_continue}
"*password:" {send "$pwd\r"}
}
interact  # 保持在远程终端

参考:https://www.cnblogs.com/saneri/p/10819348.html

posted @ 2020-08-19 14:14  stdpain  阅读(451)  评论(0编辑  收藏  举报