ttyd一个好用的网页版的终端工具

项目地址:https://github.com/tsl0922/ttyd

该文章的环境是ubuntu18.04

Linux下需要手动编译

sudo apt-get install build-essential cmake git libjson-c-dev libwebsockets-dev
git clone https://github.com/tsl0922/ttyd.git
cd ttyd && mkdir build && cd build
cmake ..
make
sudo make install

如果是在mac上可直接通过brew安装

brew install ttyd

基本使用

ttyd bash # 默认监听本地7681端口
ttyd -p 8080 bash # 指定本地端口8080

即通过127.0.0.1:7681或者127.0.0.1:8080可访问上述打开的shell…
在这里插入图片描述

但是如果你想局域网的其他机器也能访问,需要使用nginx反向代理,将请求的数据都转发给ttyd监听的端口!

这里我采用的方法是使用ssh进行端口转发,可以实现内网机器都能访问。(如果提供任意一台外网机器也可以实现内网穿透让外网机器都能访问)

需要先修改配置文件/etc/ssh/sshd_configGatewayPortsyes

sudo ssh -fCNL *:80:localhost:7681 moddemod@localhost

上面的命令意思就是让局域网任意IP可以访问执行该命令机器的80端口,且将80端口的数据转发给localhost:7681即ttyd。

在这里插入图片描述

更多使用参考:https://github.com/tsl0922/ttyd/wiki/Example-Usage

猜你喜欢

转载自blog.csdn.net/weixin_43833642/article/details/106975511