Github每日精选(第26期):在web端操作终端gotty

gotty

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的使用

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/

访问浏览器,这时候就可以输入任何命令了。

在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

go2coding

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值