Скорее всего проблемы с правами доступа к ключу. Попробуйте :chmod 600 key _file.pem
Возможно:
set count 0
expect {
"Password:" {
if {[incr count] == 2} {
# this is the 2nd time, send Ctrl+C
send -- \x3
expect eof
error "incorrect password"
} else {
send -- "$2\r"
exp_continue
}
}
"$prompt"
}
# successfully logged in.
send -- something
...