One - One Code All

Blog Content

Mac 让 iTerm2 自动登陆ssh

Linux-Mac   2018-03-03 23:02:05

用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里面配置。


command+o 唤醒编辑列表,在general中,send text at start 输入:

item2login.sh 22 root 192.168.1.1 password

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

如果要新增,只需要更改后面的几个参数即可,不必重新配置文件。


上一篇:mac中pypy3安装cvxopt
下一篇:iterm2命令快捷键mac命令行shell光标移动到行首Ctrl A

The minute you think of giving up, think of the reason why you held on so long.