参考链接:
https://cloud.tencent.com/developer/article/1561750
安装expect:
brew install expect
如果遇到 man 目录的权限问题可以执行以下命令后在执行安装命令:
sudo chown -R $(whoami) /usr/local/share/man/man5
创建 except 脚本:
#!/usr/bin/expect
set timeout 30
spawn ssh -p [lindex $argv 0] [lindex $argv 1]@[lindex $argv 2]
expect {
"(yes/no)?"
{send "yes\n";exp_continue}
"password:"
{send "[lindex $argv 3]\n"}
}
interact
这里[lindex $argv 0], [lindex $argv 1],[lindex $argv 2], [lindex $argv 3] 分别代表着 端口号 用户名 服务器地址 密码 4个参数。 还需要给脚本执行权限
sudo chmod +x /Users/macbook/source/m-job/iterm2login.sh
新建 profiles
iTerm2 -> Preferences -> Profiles
/Users/macbook/source/m-job/iterm2login.sh 22 root ip地址 您的密码