【转载】Mac 让 iTerm2 记住用户名密码

使用场景

刚刚用iTerm2的时候,总是要一遍遍的敲用户名、密码。 我在想, 能不能像Windows的软件一样,可以直接让软件记住。然后只要点击一下,就直接ssh到远程服务器上面去了。
之后经过搜索,可以用expect脚本实现。

实现代码

#!/usr/bin/expect

set timeout 30
spawn ssh -p [lindex $argv 0] [lindex $argv 1]@[lindex $argv 2]
expect {
        "(yes/no)?"
        {send "yes
";exp_continue}
        "password:"
        {send "[lindex $argv 3]
"}
}
interact

使用参数说明

这里[lindex $argv 0], [lindex $argv 1], [lindex $argv 2], [lindex $argv 3] 分别代表着4个参数。

操作流程

  • 将这个文件 item2login.sh 复制到 /usr/local/bin 就可以了。 然后在iTerm2里面配置。
  • 打开ITerm2的Profiles菜单并添加新的profile
  • 在Command栏下的”Send text at start“处填入:item2login.sh 22 chenyuan 192.168.230.133 chenyuan

参数说明

sh脚本 + 端口 + 账号 + IP + 密码

参考连接

原文地址:https://www.cnblogs.com/damingge/p/6710224.html