mac篇---使用iTerm2快捷连接SSH

大家都知道使用iTerm2连接shh 使用命令 ssh -p22 root@129.10.10.1,然后输入密码即可。

但是每次都输入还是比较麻烦的。iTerm2为我们提供了快捷的方式。三步即可完成此项设置。方法如下:

1,编辑命令文本

样本:

输入:~/.ssh/ 然后回车

新建一个shell文件,命名为iterm2login.sh,里面写入内容:

#!/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

 注:要记得给sh文件赋予权限  chmod 777 iterm2login.sh

语法说明:shell文件是expect语言脚本,可以自动和网络交互,基本原理就是解析ssh的命令文本返回,根据文本内容匹配,执行对应的操作,send就是模拟人工输入。

2,设置调用命令

第二步: 设置iterm2,在profiles中建立一个新profile,配置如192.168.100.127中描述

Name: 填写便于记忆的名称
Login shell -> Send text at start: /Users/yuml/bin/iterm2login.sh 22 root 192.168.100.127 password

第三步: 运行profile, 在iterm2的顶部工具栏有一栏Profiles,就可以看到对应的profle,双击就可以了

4.ssh登录 The authenticity of host 192.168.0.xxx can't be established. 的问题

用ssh登录一个机器(换过ip地址),提示输入yes后,屏幕不断出现y,只有按ctrl + c结束

错误是:The authenticity of host 192.168.0.xxx can't be established.

执行ssh  -o StrictHostKeyChecking=no  192.168.0.xxx 就OK

 

原文地址:https://www.cnblogs.com/yuanfang0903/p/10879565.html