-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* version info from ldflags * remove README.md version node * bugfix golang slice address take mode * 重构&优化 - 支持分组 - 支持显示/隐藏主机详情(show_detail) - 支持options(目前仅支持ServerAliveInterval) - 允许配置文件中server默认值为空 - 允许指定配置文件目径 - 修复终端窗口大小改变时无法自适应的bug * 重构&优化 - 支持编辑功能 - 增加Log功能 * 调整分隔线长度 * 增加新建、移除功能 * 优化错误提示 * update gif path * update gif path * Update README.md * update help info
- Loading branch information
Showing
13 changed files
with
904 additions
and
337 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
servers.json | ||
releases/ | ||
releases/ | ||
.idea/ | ||
main | ||
test.go | ||
app.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,92 +1,95 @@ | ||
# autossh | ||
|
||
go写的一个ssh远程客户端。可一键登录远程服务器,主要用来弥补Mac/Linux Terminal ssh无法保存密码的不足。 | ||
一个ssh远程客户端,可一键登录远程服务器,主要用来弥补Mac/Linux Terminal ssh无法保存密码的不足。 | ||
|
||
使用Mac开发已有几个月,一直没有找到比较好用的ssh客户端。SecureCRT有Mac版,始终觉得没有自带的Terminal好用。而Terminal只是一个终端, | ||
对于经常要通过ssh远程操作的人来说,功能还是太弱了。 | ||
![演示](https://raw.githubusercontent.com/islenbo/autossh/b3e18c35ebced882ace59be7843d9a58d1ac74d7/doc/images/ezgif-1-a4ddae192f.gif) | ||
|
||
其间,我也试过自己写一些shell来辅助,如:`alias sshlocal="ssh [email protected]"`,但是它无法记住密码自动登录。 | ||
再如,使用sshpass实现记住密码,但用着还是各种别扭。原因: | ||
- 这些功能都是编写shell实现的,本人对shell编程并不擅长 | ||
- shell脚本逼格不够高 | ||
## 版本说明 | ||
这是一个全新的autossh,无法兼容v0.2及以下版本,升级前请做好备份!新版配置文件由原来的`servers.json`改为`config.json`, | ||
升级时可将旧配置文件的列表插入到新配置文件的`servers`节点下 | ||
|
||
最后,下定决心用golang写一个ssh client。为什么不用C或者Java?因为golang是世界上最好的编译语言,PHP是世界上最好的脚本语言。 | ||
注:旧版servers中method=pem需要更新为method=key | ||
|
||
## 版本 | ||
v0.2 | ||
## 功能说明 | ||
- 支持分组 | ||
- 支持显示/隐藏主机详情(show_detail) | ||
- 支持options(目前仅支持ServerAliveInterval) | ||
- 允许配置文件中server默认值为空 | ||
- 允许指定配置文件目径 | ||
- 修复终端窗口大小改变时无法自适应的bug | ||
|
||
## 下载 | ||
[https://github.com/islenbo/autossh/releases](https://github.com/islenbo/autossh/releases) | ||
|
||
## 配置 | ||
下载编译好的二进制包autossh,在autossh同级目录下新建一个servers.json文件。 | ||
编辑servers.json,内容可参考server.example.json | ||
## 安装 | ||
- 下载编译好的二进制包autossh,放在指目录下,如`~/autossh`或`/usr/loca/autossh` | ||
- 同级目录下新建`config.json`文件,参考`config.example.json` | ||
- 将安装目录加入环境变量中,或指定别名`alias autossh=your autossh path/autossh` | ||
|
||
## config.json | ||
```json | ||
[ | ||
{ | ||
"name": "vagrant", // 显示名称 | ||
"ip": "192.168.33.10", // 服务器IP或域名 | ||
"port": 22, // 端口 | ||
"user": "root", // 用户名 | ||
"password": "vagrant", // 密码 | ||
"method": "password" // 认证方式,目前支持password和pem | ||
{ | ||
"show_detail": true, // 显示主机详情 | ||
"options": { // 全局配置 | ||
"ServerAliveInterval": 30 // 发送心跳包时间,同 ssh -o ServerAliveInterval=30 | ||
}, | ||
{ | ||
"name": "ssh-pem", | ||
"ip": "192.168.33.11", | ||
"port": 22, | ||
"user": "root", | ||
"password": "your pem file password or empty", // pem密钥密码,若无密码则留空 | ||
"method": "pem", // pem密钥认证 | ||
"key": "your pem file path" // pem密钥文件绝对路径 | ||
} | ||
// ...可配置多个 | ||
] | ||
``` | ||
保存servers.json,执行autossh,即可看到相应服务器信息,输入对应序号,即可自动登录到服务器 | ||
![登录演示](https://github.com/islenbo/autossh/raw/master/doc/images/demo.gif) | ||
"servers": [ | ||
{ | ||
"name": "vagrant", // 显示名称 | ||
"ip": "192.168.33.10", // 主机地址 | ||
"port": 22, // 端口号,可省略,默认为22 | ||
"user": "root", // 用户名 | ||
"password": "vagrant", // 密码,使用无密码的key登录时可省略 | ||
"method": "password", // 认证方式,可省略,默认值为password,可选项有password、key | ||
"key": "", // 密钥路径,method=key时有效,可省略,默认为~/.ssh/id_rsa | ||
"options": { // 自定义配置,会覆盖配置中相同的值 | ||
"ServerAliveInterval": 20 | ||
} | ||
}, | ||
{ | ||
"name": "vagrant-key", | ||
"ip": "192.168.33.10", | ||
"user": "root", | ||
"method": "key" | ||
} | ||
], | ||
"groups": [ | ||
{ | ||
"group_name": "your group name", | ||
"prefix": "a", | ||
"servers": [ | ||
{ | ||
"name": "example1", | ||
"ip": "192.168.33.10", | ||
"user": "root", | ||
"password": "root" | ||
}, | ||
{ | ||
"name": "example2", | ||
"ip": "192.168.33.10", | ||
"user": "root", | ||
"password": "root" | ||
} | ||
] | ||
}, | ||
{ | ||
"group_name": "group2", | ||
"prefix": "b", | ||
"servers": [ | ||
] | ||
} | ||
] | ||
} | ||
|
||
## 高级用法 | ||
设置alias,可在任意目录下调用 | ||
```bash | ||
[root@localhost ~]# vim /etc/profile | ||
在行尾追加 alias autossh="~/autossh_path/autossh" | ||
[root@localhost ~]# . /etc/profile | ||
``` | ||
更多快捷操作,可调用 `--help` 查看 | ||
```bash | ||
[root@localhost autossh]# autossh --help | ||
go写的一个ssh远程客户端。可一键登录远程服务器,主要用来弥补Mac/Linux Terminal ssh无法保存密码的不足。 | ||
基本用法: | ||
直接输入autossh不带任何参数,列出所有服务器,输入对应编号登录。 | ||
参数: | ||
-v, --version 显示 autossh 的版本信息。 | ||
-h, --help 显示帮助信息。 | ||
操作: | ||
list 显示所有server。 | ||
add <name> 添加一个 server。如:autossh add vagrant。 | ||
edit <name> 编辑一个 server。如:autossh edit vagrant。 | ||
remove <name> 删除一个 server。如:autossh remove vagrant | ||
``` | ||
|
||
## Q&A | ||
- Q: Downloads中为什么没有Windows的包? | ||
- A: Windows下有很多优秀的ssh工具,autossh主要面向Mac/Linux群体。 | ||
|
||
- Q: 为什么要设置alias而不将autossh放到/usr/bin/下? | ||
- A: autossh核心文件有两个,autossh和servers.json且必须处于同级目录下,所以建议放在其他目录,通过alias调用。 | ||
- A: Windows下有很多ssh工具,autossh主要是面向Mac/Linux群体。 | ||
|
||
## 编译 | ||
go build main.go | ||
|
||
## 依赖包 | ||
- golang.org/x/crypto/ssh | ||
|
||
## TODO | ||
- [x] -v, --version 查看版本号 | ||
- [x] -h, --help 显示帮助 | ||
- [x] list 显示所有server | ||
- [x] add 添加一个server | ||
- [x] remove name 删除一个server | ||
- [x] edit name 编辑一个server | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
{ | ||
"show_detail": true, // 显示主机详情 | ||
"options": { // 全局配置 | ||
"ServerAliveInterval": 30 // 发送心跳包时间,同 ssh -o ServerAliveInterval=30 | ||
}, | ||
"servers": [ | ||
{ | ||
"name": "vagrant", // 显示名称 | ||
"ip": "192.168.33.10", // 主机地址 | ||
"port": 22, // 端口号,可省略,默认为22 | ||
"user": "root", // 用户名 | ||
"password": "vagrant", // 密码,使用无密码的key登录时可省略 | ||
"method": "password", // 认证方式,可省略,默认值为password,可选项有password、key | ||
"key": "", // 密钥路径,method=key时有效,可省略,默认为~/.ssh/id_rsa | ||
"options": { // 自定义配置,会覆盖配置中相同的值 | ||
"ServerAliveInterval": 20 | ||
} | ||
}, | ||
{ | ||
"name": "vagrant-key", | ||
"ip": "192.168.33.10", | ||
"user": "root", | ||
"method": "key" | ||
} | ||
], | ||
"groups": [ | ||
{ | ||
"group_name": "your group name", | ||
"prefix": "a", | ||
"servers": [ | ||
{ | ||
"name": "example1", | ||
"ip": "192.168.33.10", | ||
"user": "root", | ||
"password": "root" | ||
}, | ||
{ | ||
"name": "example2", | ||
"ip": "192.168.33.10", | ||
"user": "root", | ||
"password": "root" | ||
} | ||
] | ||
}, | ||
{ | ||
"group_name": "group2", | ||
"prefix": "b", | ||
"servers": [ | ||
] | ||
} | ||
] | ||
} |
Oops, something went wrong.