expect 实现iterm2自动加载pem登录跳板机
阅读原文时间:2023年07月08日阅读:1

#!/usr/bin/expect

set timeout
spawn ssh -i xx.pem user@59.151.78.78 -p
expect {
"connecting (yes/no)?" { send "yes\r"; }
"passphrase for key" { send "password\r" }
}
interact

执行方法 sudo ~/skip/ssh-login.sh

#!/usr/bin/expect -f
set ip [lindex $argv ] //接收第一个参数,并设置IP
set password [lindex $argv ] //接收第二个参数,并设置密码
set timeout //设置超时时间
spawn ssh root@$ip //发送ssh请滶
expect { //返回信息匹配
"*yes/no" { send "yes\r"; exp_continue} //第一次ssh连接会提示yes/no,继续
"*password:" { send "$password\r" } //出现密码提示,发送密码
}
interact //交互模式,用户会停留在远程服务器上面.

参考文章:https://www.cnblogs.com/lixigang/articles/4849527.html

手机扫一扫

移动阅读更方便

阿里云服务器
腾讯云服务器
七牛云服务器

你可能感兴趣的文章