1.进入:
~/.ssh/test // test无后缀名
2.编辑内容
# 编辑汉字部分
set user 用户名
set host 主机IP
set password 密码
spawn ssh $user@$host
expect "*assword:*"
send "$password\r"
interact
expect eof
3.添加配置

第一步:点击profiles => open profiles 打开profiles
第二步:点击profiles面板中的edit profiles
第三步:点击preferences面板中左侧下方的加号,添加一项
第四步:在command中添加expect ~/.ssh/test
4.重启iterm2
5.再次打开iterm2, 使用快捷键command+o打开profiles面板,点击配置名连接服务器
报错:A session ended very soon after starting. Check that the command in profile "New Profile" is correct.

解决:删除~/.ssh/known_hosts中对应的ip,重新连接,成功!
原文:https://www.cnblogs.com/lwenl/p/14872127.html