98 lines
3.0 KiB
Markdown
98 lines
3.0 KiB
Markdown
# Gotty 的安装与配置
|
||
|
||
## 下载与安装
|
||
|
||
到 <https://github.com/yudai/gotty> 的 Release 中下载对应版本的 gotty 程序,解压后从命令行运行即可。
|
||
|
||
## 配置文件
|
||
|
||
可以通过命令行参数运行 gotty 程序,也可以通过 --config 参数为其指定配置文件,gotty 源码中有参考配置文件,以下是一个比较简单实用的配置(“//”为行注释):
|
||
|
||
```sh
|
||
// [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
|
||
|
||
// [map[string]string] The default environment variables, as an object.
|
||
environment = {"TERM" = "xterm-256color"}
|
||
```
|
||
|
||
上面配置文件使 gotty 启用 https,使用用户名“user”和密码“pass”来登陆。并定制了网页标题头。
|
||
|
||
https 依赖于 crt 和 key 这两个证书文件,你可以用以下命令创建临时的证书文件(或到证书管理网站申请正式证书)。
|
||
|
||
```sh
|
||
openssl req -x509 -nodes -days 9999 -newkey rsa:2048 -keyout gotty.key -out gotty.crt
|
||
```
|
||
|
||
## 运行
|
||
|
||
一个可以与多个客户端分享终端,并且使用配置文件的命令和参数如下:
|
||
|
||
```sh
|
||
gotty --config=<config file> tmux new -A -s gotty
|
||
```
|
||
|
||
如果配置文件与本文示例一致,则上列命令与下列命令等同:
|
||
|
||
```sh
|
||
gotty -t --tls-crt=./gotty.crt --tls-key=./gotty.key -w -p "9000" -c "user:pass" tmux new -A -s gotty
|
||
```
|
||
|
||
## RC 文件
|
||
|
||
可以使用 gotty bash 来启动一个 bash 终端,但是该终端没有初始化,可以通过 --rcfile 参数来指定一个 rc 文件:
|
||
|
||
```sh
|
||
gotty --config=<config file> --rcfile <rc file>
|
||
```
|
||
|
||
一个参考 RC 文件如下:
|
||
|
||
```rc
|
||
# gotty.rc
|
||
export TERM=xterm-256color
|
||
source ~/.bash_profile
|
||
```
|
||
|
||
其中 export TERM=xterm-256color 是为了解决某些应用不知道 bash 类型而设置的。当应用不知道 bash 类型时,将到导致无法运行(如 top 和 tmux)或终端无法彩色显示等问题。
|
||
|
||
## 参考文献
|
||
|
||
1. [GoTTY:把你的 Linux 终端放到浏览器里面](https://zhuanlan.zhihu.com/p/26590894)
|