2017年3月11日 星期六

ttyd - 從瀏覽器以 ssh 登入 linux 主機

一個 daemon, 可以從瀏覽器用 ssh 登入主機。

編譯與執行
https://github.com/tsl0922/ttyd

apt-get install libwebsockets-dev
apt-get install libjson-c-dev
cmake .

192.168.1.9 是我的 eth0 ip, 預設 port 是 7681, 紅色是執行的指令
run
descent@u64:ttyd$ ./ttyd ssh descent@192.168.1.9
[1474856081:4555] NOTICE: Initial logging level 7
[1474856081:4556] NOTICE: Libwebsockets version: 1.7.1 unknown-build-hash
[1474856081:4556] NOTICE: IPV6 not compiled in
[1474856081:4557] NOTICE: libev support compiled in but disabled
[1474856081:4560] NOTICE:  Threads: 1 each 1024 fds
[1474856081:4560] NOTICE:  mem: platform fd map:  8192 bytes
[1474856081:4561] NOTICE:  mem: per-conn:          808 bytes + protocol rx buf
[1474856081:4561] NOTICE:  canonical_hostname = u64
[1474856081:4562] NOTICE:  Compiled with OpenSSL support
[1474856081:4562] NOTICE:  Using non-SSL mode
[1474856081:4847] NOTICE:  SSL ECDH curve 'prime256v1'
[1474856081:4848] NOTICE:  Listening on port 7681
[1474856081:4848] NOTICE: TTY configuration:
[1474856081:4848] NOTICE:   start command: ssh descent@192.168.1.9
[1474856081:4848] NOTICE:   reconnect timeout: 10s
[1474856081:4848] NOTICE:   close signal: SIGHUP (1)
[1474856105:2092] NOTICE: HTTP connect from 192.168.1.9 (192.168.1.9), path: /
[1474856105:2781] NOTICE: HTTP connect from 192.168.1.9 (192.168.1.9), path: /auth_token.js
[1474856105:3081] NOTICE: client connected from 192.168.1.9 (192.168.1.9), total: 1
[1474856105:3085] NOTICE: started process, pid: 19400
[1474856218:7906] NOTICE: HTTP connect from 192.168.1.9 (192.168.1.9), path: /
[1474856218:8341] NOTICE: HTTP connect from 192.168.1.9 (192.168.1.9), path: /auth_token.js
[1474856218:9817] NOTICE: client connected from 192.168.1.9 (192.168.1.9), total: 2
[1474856218:9820] NOTICE: started process, pid: 19546

從瀏覽器輸入 http://192.168.1.9:7681/ 就會出現 ssh 登入畫面。

從瀏覽器登入

ref:
ttyd 1.0.0 发布,C 语言编写的命令行程序

沒有留言:

張貼留言

使用 google 的 reCAPTCHA 驗證碼, 總算可以輕鬆留言了。

我實在受不了 spam 了, 又不想讓大家的眼睛花掉, 只好放棄匿名留言。這是沒辦法中的辦法了。留言的朋友需要有 google 帳號。