#!/usr/bin/expect -f set host 堡垒机ip set port 堡垒机端口 set user 登陆用户 set key_file 登陆密钥 set authenticator [exec bash -c {/usr/bin/totp 堡垒机对应密钥名称}] set timeout -1 spawn ssh -i $key_file -p $port $user@$host expect "*auth*" send "$authenticator\r" interact expect eof