第一步: 創(chuàng)建shell命令文件,具體的路徑自己放置,示例: ~/.ssh/login.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
第二步:賦予文件可執(zhí)行權(quán)限
chmod +x ~/.ssh/login.sh
第三步: 設置iterm2,在profiles中建立一個新profile,配置如下:

img
profile設置
1、Name: 填寫便于記憶的名稱
2、Login shell -> Send text at start:
~/.ssh/login.sh 端口 root ip地址 password
第四步: 運行profile, 在iterm2的頂部工具欄有一欄Profiles,就可以看到對應的profle,雙擊就可以了。