[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图标就应该可以看到一些菜单了。
目录切换
: 里面是平常我使用的常用命令 netease
: 就是平时需要远程登录的服务器
点击其中的菜单项,将会使用iTerm打开窗口并运行命令(我配置的是iTerm)。
-
安装Shuttle
首先到Shuttle的官网下载:
下载地址:https://github.com/fitztrev/shuttle/releases
然后把Shuttle复制到Application文件夹下即可 -
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",
- }
- ]
- }
配置了两个快捷菜单:
- SSH – MayiYun 用来登陆我的蚂蚁云服务器
- Open – ADB Shell 做安卓开发的时候,快速打开adb
总结
当然,这里只是简单介绍了shuttle的基本用法,还有更多其他功能值得去探索~