Reference link:
https://cloud.tencent.com/developer/article/1561750
Install expect:
brew install expect
If you encounter permission problems in the man directory, you can execute the installation command after executing the following command:
sudo chown -R $(whoami) /usr/local/share/man/man5
Create the except script:
#!/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
Here [lindex $argv 0], [lindex $argv 1], [lindex $argv 2], [lindex $argv 3] respectively represent the four parameters of port number, username, server address, and password. You also need to give the script execute permission
sudo chmod +x /Users/macbook/source/m-job/iterm2login.sh
New profiles
iTerm2 -> Preferences -> Profiles
/Users/macbook/source/m-job/iterm2login.sh 22 root ip地址 您的密码