安装ttyd
因为管理服务器需要登录堡垒机需要双因子认证,麻烦得很这才想到了用ttyd
我的安装是直接下载github上的文件,放在了系统环境变量PATH中的目录里面:
1 | curl -L -o /usr/local/bin/ttyd https://github.com/tsl0922/ttyd/releases/download/1.7.7/ttyd.x86_64 |
编辑配置文件
看官方介绍能支持不少功能:
1 | Built on top of libuv and WebGL2 for speed |
我主要用到的是文件传输功能,参考wiki:
https://github.com/tsl0922/ttyd/wiki/Example-Usage
https://github.com/tsl0922/ttyd/wiki/Client-Options
1 | enable ZMODEM / lrzsz file transfer support: ttyd -t enableZmodem=true bash |
下面来编写一个systemd service让ttyd自启动:
编辑/etc/systemd/system/ttyd.service
enableTrzsz=true 启用这个是因为lrzsz上传超过100M终端会乱码;
enableZmodem=true 这个是启用lrzsz,这个我测试100M以内的文件能够正常工作
-c 是配置简单的认证用户和密码;
-W 是启用可写,如果不加上这个参数终端是没法输入的;
1 | [Unit] |
重新读取所有daemon:
1 | systemctl daemon-reload |
加入开机自启动:
1 | systemctl enable ttyd |
启动ttyd:
1 | systemctl start ttyd |
安装lrzsz:
1 | dnf install lrzsz |
安装trzsz:
1 | pip install trzsz |
然后就能通过浏览器访问了:localhost:7681
不过我这边为了能够跳过堡垒机直接访问终端,我还在服务器上部署了一个nginx,然后通过nginx反代了ttyd服务;我的配置如下:
1 | location /ttyd/ { |