1、cd ~/.ssh
在.ssh下创建文件"shell" (其中<>部分 替换为自己的用户名、服务器ip、密码)
#!/usr/bin/expect -f
set user <用户名>
set host <服务器ip>
set password <登录服务器的密码>
set timeout -1
spawn ssh $user@$host
expect "*assword:*"
send "$password\r"
interact
expect eof
2、打开iterm2
3、选择Profiles
建议除Default外,新建Profile name ,然后在新建的profile Command模块上选择 command: 填入自己在第一步中创建的shell
将这个命令中的部分shell 替换为第一步中自己创建的文件名
expect ~/.ssh/shell