mac下iterm2配置安裝,通過expact實現保存賬號,及通過跳板登陸配置


在參考了幾款mac不錯的ssh工具外,最終選擇使用iterm2。本來打算用FinalShell,安裝后發現其icon在訪達中根本不現實,而且每次訪問還需要輸入管理員賬號密碼,強迫症根本受不了...

  • 官網下載

https://www.iterm2.com/downloads.html

  • 安裝

雙擊.app即可

  • 配置

有趣的在於后面的配置

采用expact腳本方式來完成對遠程登陸的賬號密碼配置來進行配置

profiles-open profiles

 選擇Login shell

Send text at start 填寫  /Users/whk/dev/defaultlogin.sh 22 root 服務器IP 密碼

 /Users/whk/dev/defaultlogin.sh 文件如下:

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

普通登陸參考👆上面的Done!

 

  • 跳板登陸內網

接下來,來點更有意思的,服務器跳板登陸設置

shell文件如下:

#!/usr/bin/expect
set host [lindex $argv 0]

set TERMSERV 跳板機IP
set USER 跳板機用戶名
set PASSWORD 跳板機密碼
set UATUN 內網服務器用戶名
set UATPWD 內網服務器密碼

# 登錄跳板機
spawn ssh -l $USER $TERMSERV
expect {
        "yes/no" {send "yes\r";exp_continue;}
         "*password:*" { send "$PASSWORD\r" }
        }
# 登錄內網
expect "*跳板機用戶名@*" {send "ssh -l $UATUN $host\r"}
expect {
        "yes/no" {send "yes\r";exp_continue;}
        "*password:*" { send "$UATPWD\r" }
        }
interact

Send text at start 填寫  /Users/whk/dev/defaultlogin.sh 22 服務器IP

Done!

 

安裝配置主題/oh My Zsh/字體/高亮等,可參考 Mac OS 終端利器 iTerm2

相關命令

查看當前系統所支持的命令行環境: cat /etc/shells

查看zsh版本,亦可判斷是否安裝:zsh --version

切換shell環境,新開窗口生效:chsh -s /bin/zsh

item2快捷鍵

命令 說明
command + t 新建標簽
command + w 關閉標簽
command + 數字 command + 左右方向鍵 切換標簽
command + enter 切換全屏
command + f 查找
command + d 垂直分屏
command + shift + d 水平分屏
command + option + 方向鍵 command + [ 或 command + ] 切換屏幕
command + ; 查看歷史命令
command + shift + h 查看剪貼板歷史
ctrl + u 清除當前行
ctrl + l 清屏
ctrl + a 到行首
ctrl + e 到行尾
ctrl + f/b 前進后退
ctrl + p 上一條命令
ctrl + r 搜索命令歷史

 

參考地址:

https://www.jianshu.com/p/3757554b907d

https://segmentfault.com/a/1190000009826457

https://www.jianshu.com/p/0f3dcec21a97

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM