同事写的auto ssh login script:
#!/usr/bin/expect -f
# by gwang
# default password list
array set passwd {
0 "password1"
1 "password2"
2 "password3"
}
# try login
spawn $env(SHELL)
match_max 100000
send -- "ssh -p $port $user@$ip\r"
foreach i [array names passwd] {
expect {
"(yes/no)" {
send -- "yes\r"
exp_continue
}
"password:" {
send -- "$passwd($i)\r"
}
"Last login" {
break
}
}
}
interact
由于ssh client默认支持的密码错误重试是3, 所以这里只支持3个备选密码。
Google for "ssh client password retry" and find link which could help:
ssh login retry 介绍了只要修改ssh client配置文件里/etc/ssh/ssh_config的NumberOfPasswordPrompts选项就可以了。无需重启sshd...