大家都知道使用iTerm2连接shh 使用命令 ssh -p22 root@129.10.10.1,然后输入密码即可。但是对于我们的服务器或者测试服务器,每次都这么手动ssh连接太慢了而且麻烦,我们可以考虑使用比较快捷的方式去连接的。

1、在~/.ssh下,新建文件,比如login,或者test1等;
css
2、

1
2
3
4
5
6
7
8
9
10
11
#!/usr/bin/expect -f
set user root
set host 192.168.1.109
set password test123###
set timeout -1

spawn ssh $user@$host
expect "*assword:*"
send "$password\r"
interact
expect eof

3、如果是其他的端口,在set一个port xxxx,xxxx对应你的端口;
4、打开iterm2的Profiles,点击+号,新增一个profile,name写自己连接主机的名称,然后在command上选择command,把:

1
expect ~/.ssh/login

后面的login对应你建立的文件名称
5、使用的时候,直接在iterm2上面的Profiles选择你填写的用户名即可。
css

感谢您的阅读,本文由 李经纶 版权所有。如若转载,请注明出处:李经纶个人博客(https://chinalijinglun.github.io//2018/04/27/登录/