Mac 让 iTerm2 记住用户名密码 expect 脚本

    xiaoxiao2025-11-10  8

    刚刚用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\n";exp_continue} "password:" {send "[lindex $argv 3]\n"} } interact

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

    将这个文件 item2login.sh 复制到 /usr/local/bin 就可以了。 然后在iTerm2里面配置。

    如图1:

    然后看一条具体的实例

    item2login.sh 22 chenyuan 192.168.230.133 chenyuan

    脚本 端口号 用户名 服务器地址 密码 一定要一一对应

    http://codingstyle.cn/topics/31

    相关资源:iterm2使用rzsz的sh脚本 mac使用
    最新回复(0)