你們都知道使用iTerm2鏈接shh 使用命令 ssh -p22 root@129.10.10.1,而後輸入密碼便可。shell
可是每次都輸入仍是比較麻煩的。iTerm2爲咱們提供了快捷的方式。三步便可完成此項設置。方法以下:bash
1,編輯命令文本網絡
樣本:ssh
輸入:~/.ssh/ 而後回車工具
新建一個shell文件,命名爲iterm2login.sh,裏面寫入內容:ui
#!/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
注:要記得給sh文件賦予權限 chmod 777 iterm2login.shspa
語法說明:shell文件是expect語言腳本,能夠自動和網絡交互,基本原理就是解析ssh的命令文本返回,根據文本內容匹配,執行對應的操做,send就是模擬人工輸入。code
2,設置調用命令blog
第二步: 設置iterm2,在profiles中創建一個新profile,配置如192.168.100.127中描述ip
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