gotty
是将您的终端共享为 Web 应用程序,我们都知道我们可以使用第三方来连接我们的服务器。如果在外地出差,别的电脑上并没有连接终端的第三方软件时,是否可以通过浏览器的方式来连接服务器,并进行简单的操作呢?
GoTTY
是一个简单的命令行工具,可将您的 CLI 工具转换为 Web 应用程序。
github 的地址在这里。
先安装go
语言
apt install golang
在github上下载gotty_linux_amd64.tar.gz
并安装:
tar -zxvf gotty_linux_amd64.tar.gz
sudo mv ./gotty /usr/bin
测试安装情况:
gotty -v
gotty version 1.0.1
GoTTY命令的常用参数:
--address value, -a value IP address to listen (default: "0.0.0.0") [$GOTTY_ADDRESS]
--port value, -p value Port number to liten (default: "8080") [$GOTTY_PORT]
--permit-write, -w Permit clients to write to the TTY (BE CAREFUL) [$GOTTY_PERMIT_WRITE]
--credential value, -c value Credential for Basic Authentication (ex: user:pass, default disabled) [$GOTTY_CREDENTIAL]
--random-url, -r Add a random string to the URL [$GOTTY_RANDOM_URL]
--random-url-length value Random URL length (default: 8) [$GOTTY_RANDOM_URL_LENGTH]
--tls, -t Enable TLS/SSL [$GOTTY_TLS]
--tls-crt value TLS/SSL certificate file path (default: "~/.gotty.crt") [$GOTTY_TLS_CRT]
--tls-key value TLS/SSL key file path (default: "~/.gotty.key") [$GOTTY_TLS_KEY]
--tls-ca-crt value TLS/SSL CA certificate file for client certifications (default: "~/.gotty.ca.crt") [$GOTTY_TLS_CA_CRT]
--index value Custom index.html file [$GOTTY_INDEX]
--title-format value Title format of browser window (default: "{{ .command }}@{{ .hostname }}") [$GOTTY_TITLE_FORMAT]
--reconnect Enable reconnection [$GOTTY_RECONNECT]
--reconnect-time value Time to reconnect (default: 10) [$GOTTY_RECONNECT_TIME]
--max-connection value Maximum connection to gotty (default: 0) [$GOTTY_MAX_CONNECTION]
--once Accept only one client and exit on disconnection [$GOTTY_ONCE]
--timeout value Timeout seconds for waiting a client(0 to disable) (default: 0) [$GOTTY_TIMEOUT]
--permit-arguments Permit clients to send command line arguments in URL (e.g. http://example.com:8080/?arg=AAA&arg=BBB) [$GOTTY_PERMIT_ARGUMENTS]
--width value Static width of the screen, 0(default) means dynamically resize (default: 0) [$GOTTY_WIDTH]
--height value Static height of the screen, 0(default) means dynamically resize (default: 0) [$GOTTY_HEIGHT]
--ws-origin value A regular expression that matches origin URLs to be accepted by WebSocket. No cross origin requests are acceptable by default [$GOTTY_WS_ORIGIN]
--term value Terminal name to use on the browser, one of xterm or hterm. (default: "xterm") [$GOTTY_TERM]
--close-signal value Signal sent to the command process when gotty close it (default: SIGHUP) (default: 1) [$GOTTY_CLOSE_SIGNAL]
--close-timeout value Time in seconds to force kill process after client is disconnected (default: -1) (default: -1) [$GOTTY_CLOSE_TIMEOUT]
--config value Config file path (default: "~/.gotty") [$GOTTY_CONFIG]
--version, -v print the version
在浏览器上查看top
结果:
gotty top
得到的提示如下:
root@lqp:/home/lqp# gotty top
2022/07/29 16:05:24 Server is starting with command: top
2022/07/29 16:05:24 URL: http://127.0.0.1:8080/
2022/07/29 16:05:24 URL: http://[::1]:8080/
2022/07/29 16:05:24 URL: http://192.168.100.170:8080/
2022/07/29 16:05:24 URL: http://[fe80::26f:5073:c696:dc9]:8080/
到这里以后,我们访问http://192.168.100.170:8080/
可以得到top
的结果。
top
的结果就展示在web 端上了,但是我们不能在web上进行操作,如果要进行操作,可以用如下的命令。
gotty -w bash
结果如下:
2022/07/29 16:13:04 Permitting clients to write input to the PTY.
2022/07/29 16:13:04 Server is starting with command: bash
2022/07/29 16:13:04 URL: http://127.0.0.1:8080/
2022/07/29 16:13:04 URL: http://[::1]:8080/
2022/07/29 16:13:04 URL: http://192.168.100.170:8080/
2022/07/29 16:13:04 URL: http://[fe80::26f:5073:c696:dc9]:8080/
访问浏览器,这时候就可以输入任何命令了。