[MAC] MAC上的ssh工具Shuttle 安裝與配置簡介


由於經常需要通過ssh管理遠程服務器,而Mac自帶的terminal每次都需要輸入密碼,很麻煩。

所以想找一個類似Windows下的xShell之類的工具

windows 下遠程登錄通常會使用 Xshell,而在 Mac 訪問虛擬機可以使用 shuttle

 

本文說明:

本文介紹Shuttle的安裝以及配置,主要是根據Github上的官方文檔進行翻譯說明,還有自己的一些補充,如果習慣直接看文檔的朋友,可以直接關掉這篇文章了~

Shuttle是什么

這是其在Github上的介紹:http://fitztrev.github.io/shuttle/

 

看一下官方簡介,就一句話

A simple SSH shortcut menu for macOS

顧名思義,就是一個Mac上管理SSH的工具

 

接下來,介紹一下Shuttle的用法

1. 安裝shuttle

shuttle是一個開源軟件,其源碼托管在github ( shuttle ), 通過訪問此地址,可以下載最新版本的shuttle.app

2. 配置shuttle

運行shuttle.app, 然后可以看到托盤里會出現一個“火箭”的圖標,那個就是shuttle。 點擊 圖標 -> setting -> Edit , 系統會使用文本編輯器打開一個名為:“.shuttle.json”的文件 , 此文件即為shuttle的配置文件。配置字段描述可見 (JSON Options)里的JSON Options。以下我針對性介紹一下:

  • editor: 使用什么編輯器打開.shuttle.json文件(可選值:default, nano, vi, vim或其他可在終端編輯文件的命令)
  • launch_at_login: 是否自動啟用shuttle(可選值: true, false)
  • terminal: 設置執行命令的默認終端(可選值:Terminal.app, iTerm)
  • iTerm_verison: 當terminal參數設置為iTerm時必填(可選值:stable, nightly)
  • default_theme: 設置終端主題
  • open_in: 命令窗口展示方式(可選值:tab, new)
  • show_ssh_config_hosts: 是否解析ssh config,並顯示對應的主機到菜單列表中(可選值:true, false)
  • ssh_config_ignore_hosts: 在ssh config需要忽略顯示在菜單的主機數組(值為主機名)
  • ssh_config_ignore_keywords: 在ssh config需要忽略的關鍵字

如果要將~/.ssh/config中的主機顯示到菜單中, 可以這樣定義主機的Host值:

Host work/servers/web01: 表示web01會出現在shuttle的work菜單下servers子菜單下(一種方便的目錄層級定義方式)。

也可以使用另外一種方式:

Host web01

# shuttle.name = work/servers/web01

HostName user@web01.example.com

也就是通過“# shuttle.name”開始來定義shuttle的菜單名與層級關系(注意,這個注釋必須位於 Host與HostName之前,否則顯示的菜單與實際運行的命令會錯亂)

除了以上配置項, shuttle還支持自定義命令配置, 這種方式特別適合用常用命令。

自定義命令配置是定義在.shuttle.json中的hosts鍵值中,其值為一個數組,每個item為一個對象,結構如下:

{ "菜單名": xxx (對象或數組) }

對象包含字段有:

  • cmd: 需要執行的命令
  • name: 菜單名
  • inTerminal: 命令執行窗口模式(可選值:new, tab, current)
  • theme: 終端主題
  • title: 終端顯示標題(缺失時使用name作為標題)

3. 使用shuttle

按照上面介紹的步驟完成安裝與配置后, 現在點擊shuttle圖標就應該可以看到一些菜單了。

shuttle dropmenu

目錄切換: 里面是平常我使用的常用命令 netease: 就是平時需要遠程登錄的服務器

點擊其中的菜單項,將會使用iTerm打開窗口並運行命令(我配置的是iTerm)。

 

 

  1. 安裝Shuttle

    首先到Shuttle的官網下載:
    下載地址:https://github.com/fitztrev/shuttle/releases
    然后把Shuttle復制到Application文件夾下即可

  2. Shuttle配置

    這部分比較重要,要注意一下
    通過命令 open ~/.shuttle.json 打開.shuttle.json文件

    Global settings 全局配置

    • “editor”: “VALUE”, 設置編輯器,可選項default, nano, vi, vim

    • “launch_at_login”: VALUE, 設置是否開機啟動

    • “terminal”: “VALUE”, 設置終端,一般是Terminal.app或者iTerm

    • “iTerm_version”: “VALUE”, 設置iTerm版本,分別有三種

      “iTerm_version”: “legacy”, 2.14版本

      "iTerm\_version": "stable", 最新版本
      "iTerm\_version": "nightly", nightly build 版本 
      
    • “default_theme”: “Homebrew” 設置終端主題

    • open_in”: “VALUE” 有兩個可選項 Tab 或者 new 顧名思義,新建一個Tab 或者 在新窗口執行命令

    • “show_ssh_config_hosts”: VALUE 設置是否解析config文件,默認是true
    • “ssh_config_ignore_keywords”: [“VALUE”] 設置忽略解析的關鍵字

    Command settings 命令配置

    • “cmd”: “VALUE” 設置命令
      例如 “cmd”: “ps aux | grep [s]sh”

    • “name”: “VALUE” 設置菜單欄顯示的名稱

    • “inTerminal”: “VALUE”

      new 新建一個窗口執行命令

      tab 新建一個Tab執行命令  
      current 在當前窗口執行命令
      
    • “theme”: “VALUE” 設置主題~我用的是basic

    • “title”: “VALUE” 這個標題是顯示在終端窗口的標題~

 

附上相關配置:

(1).shuttle.json 文件

{
    "_comments": [
    "Valid terminals include: 'Terminal.app' or 'iTerm'",
    "In the editor value change 'default' to 'nano', 'vi', or another terminal based editor.",
    "Hosts will also be read from your ~/.ssh/config or /etc/ssh_config file, if available",
    "For more information on how to configure, please see http://fitztrev.github.io/shuttle/"
  ],
    "editor": "default",
    "launch_at_login": true,
    "terminal": "iTerm",
    "iTerm_version": "nightly",
    "default_theme": "Homebrew",
    "open_in": "new",
    "show_ssh_config_hosts": false,
    "ssh_config_ignore_hosts": [],
    "ssh_config_ignore_keywords": [],
    "hosts": [
        {
            "cmd": "ps aux | grep defaults",
            "name": "Grep - Opens in Default-window-theme-title"
    },
        {
            "Spouses Servers": [
                {
                    "cmd": "echo '—->WARNING! Running commands<-- Are you sure? y/n'; read sure; if [ $sure == y ]; then echo running command && ps aux | grep [a]pple; else echo save to history and show... && history -s 'ps aux | grep [a]pple' && osascript -e 'tell application \"System Events\" to keystroke \"p\" using {control down}'; fi",
                    "inTerminal": "current",
                    "name": "Logs - Opens in the current active terminal window"
        },
                {
                    "Jane’s Servers": [
                        {
                            "cmd": "ssh username@blog2.example.com",
                            "inTerminal": "tab",
                            "name": "SSH blog - Opens in Tab of active window",
                            "theme": "basic",
                            "title": "title of tab"
            },
                        {
                            "cmd": "ssh username@shop1.example.com",
                            "inTerminal": "new",
                            "name": "SSH Shop - Opens in New Window",
                            "theme": "basic",
                            "title": "title of new window"
            }
          ]
        }
      ]
    },
  ]
}

 

(2)JSON格式說明

{
    "菜單名稱": [
        {
            "cmd": "需要執行的 ssh 命令",
            "inTerminal": "命令執行的窗口模式:new/tab/current",
            "name": "子菜單名",
            "theme": "終端主題:basic",
            "title": "新窗口/新標簽頁標題,缺失時使用 name 作為標題",
        }
    ]
},

 

Shuttle示例

"hosts": [
    {
      "cmd": "ssh root@192.168.0.100 -p 4000", "inTerminal": "tab", "name": "SSH - root用戶", "theme": "basic", "title": "Blue" }, { "cmd": "ssh root@192.168.0.200 -p 4000", "inTerminal": "tab", "name": "SSH - git用戶", "theme": "basic", "title": "Blue" } ]

shuttle 除了可以用來當SSH管理工具以外,還能執行多條命令操作,提高效率,只要用分號分隔即可

例如 pwd; ls; cd /; 就會按順序執行以上三條命令。  


下面的配置也可以參考:
{
  "_comments": [
    "Valid terminals include: 'Terminal.app' or 'iTerm'",
    "In the editor value change 'default' to 'nano', 'vi', or another terminal based editor.",
    "Hosts will also be read from your ~/.ssh/config or /etc/ssh_config file, if available",
    "For more information on how to configure, please see http://fitztrev.github.io/shuttle/"
  ],
  "editor": "default",
  "launch_at_login": false,
  "terminal": "Terminal.app",
  "iTerm_version": "nightly",
  "default_theme": "Homebrew",
  "open_in": "new",  
  "show_ssh_config_hosts": false,
  "ssh_config_ignore_hosts": [  ],
  "ssh_config_ignore_keywords": [  ],
  "hosts": [
    {
      "cmd": "ssh username@host",
      "name": "SSH - MayiYun",
      "inTerminal": "new",
      "theme": "basic",
    },
    {
      "cmd": "adb shell",
      "name": "Open - ADB Shell",
      "inTerminal": "new",
      "theme": "basic",
    }
  ]
}

配置了兩個快捷菜單:

  1. SSH - MayiYun 用來登陸我的螞蟻雲服務器
  2. Open - ADB Shell 做安卓開發的時候,快速打開adb

 

 

總結

當然,這里只是簡單介紹了shuttle的基本用法,還有更多其他功能值得去探索~

 


免責聲明!

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



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