在~/.ssh/下面写一个脚本,配置到iTerm2的Profiles里(当然放在其他地方也可以)。脚本内容如下:
#!/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
保存到 ~/.ssh/shellname,如果密码中有
符
号
可
以
在
符号可以在
符号可以在符号前面加个反斜杠进行转义\。
然后打开iTerm2的设置里,点开Profiles,左下角点+号新增一个配置文件,然后在Genernal->Command下选择 Command,在输入框里填入 expect ~/.ssh/shellname