方法一、使用sshpass命令
安裝sshpass
sudo brew install http://git.io/sshpass.rb
配置iTerm2
Preference>profiles 快捷鍵 command+,
新建demo profile
配置command
/usr/local/bin/sshpass -p passwrod ssh userName@ip -o StrictHostKeyChecking=no

image.png
方法二、使用expect,spawn (窗體調(diào)整后可能引起顯示異常問題),不推薦使用
新建腳本item2login.sh
#!/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
配置iTerm2
Preference>profiles 快捷鍵 command+,
新建demo2 profile
配置command
/Users/admin/sh/item2login.sh 22 userName IP password

image.png