2019-07-15 14:57:40 +08:00
|
|
|
|
# Gotty 的安装与配置
|
|
|
|
|
|
|
|
|
|
## 下载与安装
|
|
|
|
|
|
2022-10-31 11:12:27 +08:00
|
|
|
|
到 <https://github.com/sorenisanerd/gotty> 的 Release 中下载对应版本的 gotty 程序,解压后从命令行运行即可。
|
2019-07-15 14:57:40 +08:00
|
|
|
|
|
|
|
|
|
## 配置文件
|
|
|
|
|
|
2019-07-31 13:19:19 +08:00
|
|
|
|
可以通过命令行参数运行 gotty 程序,也可以通过 --config 参数为其指定配置文件,gotty 源码中有参考配置文件,以下是一个比较简单实用的配置(“//”为行注释):
|
2019-07-15 14:57:40 +08:00
|
|
|
|
|
2020-05-20 16:18:39 +08:00
|
|
|
|
```ini
|
2019-07-15 14:57:40 +08:00
|
|
|
|
// [string] Address to listen, all addresses will be used when empty
|
|
|
|
|
// address = ""
|
|
|
|
|
|
|
|
|
|
// [string] Port to listen
|
|
|
|
|
port = "9000"
|
|
|
|
|
|
|
|
|
|
// [bool] Permit clients to write to the TTY
|
|
|
|
|
permit_write = true
|
|
|
|
|
|
|
|
|
|
// [bool] Enable basic authentication
|
|
|
|
|
enable_basic_auth = true
|
|
|
|
|
|
|
|
|
|
// [string] Default username and password of basic authentication (user:pass)
|
|
|
|
|
// To enable basic authentication, set `true` to `enable_basic_auth`
|
|
|
|
|
credential = "user:pass"
|
|
|
|
|
|
|
|
|
|
// [bool] Enable TLS/SSL
|
|
|
|
|
enable_tls = true
|
|
|
|
|
|
|
|
|
|
// [string] Default TLS certificate file path
|
|
|
|
|
tls_crt_file = "./gotty.crt"
|
|
|
|
|
|
|
|
|
|
// [string] Default TLS key file path
|
|
|
|
|
tls_key_file = "./gotty.key"
|
|
|
|
|
|
|
|
|
|
// [string] Title format of browser window
|
|
|
|
|
// Available variables are:
|
|
|
|
|
// Command Command string
|
|
|
|
|
// Pid PID of the process for the client
|
|
|
|
|
// Hostname Server hostname
|
|
|
|
|
// RemoteAddr Client IP address
|
|
|
|
|
title_format = "GoTTY - {{ .Command }} ({{ .Hostname }})"
|
|
|
|
|
|
|
|
|
|
// [int] Maximum connection to gotty, 0(default) means no limit.
|
|
|
|
|
// max_connection = 1
|
|
|
|
|
|
|
|
|
|
// [bool] Accept only one client and exit gotty once the client exits
|
|
|
|
|
// once = true
|
2019-07-31 19:03:20 +08:00
|
|
|
|
|
|
|
|
|
// [map[string]string] The default environment variables, as an object.
|
|
|
|
|
environment = {"TERM" = "xterm-256color"}
|
2019-07-15 14:57:40 +08:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
上面配置文件使 gotty 启用 https,使用用户名“user”和密码“pass”来登陆。并定制了网页标题头。
|
|
|
|
|
|
|
|
|
|
https 依赖于 crt 和 key 这两个证书文件,你可以用以下命令创建临时的证书文件(或到证书管理网站申请正式证书)。
|
|
|
|
|
|
2020-05-20 16:18:39 +08:00
|
|
|
|
```bash
|
2019-07-15 14:57:40 +08:00
|
|
|
|
openssl req -x509 -nodes -days 9999 -newkey rsa:2048 -keyout gotty.key -out gotty.crt
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 运行
|
|
|
|
|
|
|
|
|
|
一个可以与多个客户端分享终端,并且使用配置文件的命令和参数如下:
|
|
|
|
|
|
2020-05-20 16:18:39 +08:00
|
|
|
|
```bash
|
2019-07-15 14:57:40 +08:00
|
|
|
|
gotty --config=<config file> tmux new -A -s gotty
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
如果配置文件与本文示例一致,则上列命令与下列命令等同:
|
|
|
|
|
|
2020-05-20 16:18:39 +08:00
|
|
|
|
```bash
|
2019-07-15 14:57:40 +08:00
|
|
|
|
gotty -t --tls-crt=./gotty.crt --tls-key=./gotty.key -w -p "9000" -c "user:pass" tmux new -A -s gotty
|
|
|
|
|
```
|
2019-07-15 14:59:05 +08:00
|
|
|
|
|
2019-07-31 19:03:20 +08:00
|
|
|
|
## RC 文件
|
|
|
|
|
|
|
|
|
|
可以使用 gotty bash 来启动一个 bash 终端,但是该终端没有初始化,可以通过 --rcfile 参数来指定一个 rc 文件:
|
|
|
|
|
|
2020-05-20 16:18:39 +08:00
|
|
|
|
```bash
|
2019-07-31 19:03:20 +08:00
|
|
|
|
gotty --config=<config file> --rcfile <rc file>
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
一个参考 RC 文件如下:
|
|
|
|
|
|
2020-05-20 16:18:39 +08:00
|
|
|
|
```ini
|
2019-07-31 19:03:20 +08:00
|
|
|
|
# gotty.rc
|
|
|
|
|
export TERM=xterm-256color
|
|
|
|
|
source ~/.bash_profile
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
其中 export TERM=xterm-256color 是为了解决某些应用不知道 bash 类型而设置的。当应用不知道 bash 类型时,将到导致无法运行(如 top 和 tmux)或终端无法彩色显示等问题。
|
|
|
|
|
|
2020-08-14 11:33:10 +08:00
|
|
|
|
## 外部参考资料
|
2019-07-15 14:59:05 +08:00
|
|
|
|
|
|
|
|
|
1. [GoTTY:把你的 Linux 终端放到浏览器里面](https://zhuanlan.zhihu.com/p/26590894)
|