Linux Mint下tty.js的安裝指南

來源:互聯網
上載者:User

Linux Mint下tty.js的安裝指南

1.簡介

tty.js是使用Node.js開發的開源Web-based SSH.通過瀏覽器即可遠端存取shell。

關於Web-based SSH的介紹參考https://en.wikipedia.org/wiki/Web-based_SSH.

關於tty.js項目,請參考下面兩個網頁,

https://www.npmjs.com/package/tty.js

https://github.com/chjj/tty.js/

2.安裝

tty.js是Node.js編寫,所在安裝之前我們要先安裝一下Node.js,參考 。

運行下面命令從github下載tty.js的原始碼,

 $ git clone https://github.com/chjj/tty.js.git

然後進入tty.js目錄下,使用npm進行安裝,

$ cd tty.js
$ sudo npm install

在運行npm install過程中,可能會出現node-gyp rebuild的錯誤,

此時我們需要運行下面兩個命令進行處理,

$ sudo apt-get install build-essential
$ sudo npm install -g node-gyp

然後再次運行sudo npm install.

3.驗證

3.1運行tty.js

在bin目錄下有個tty.js的可執行檔,運行該檔案,

$ cd bin && ./tty.js

便可啟動tty.js服務,該服務監聽8080連接埠,

開啟瀏覽器,然後輸入http://127.0.0.1:8080/可以訪問tty.js,然後點擊頁面右上方的Open Terminal便可開啟網頁終端進行命令列操作了(如所示)。

3.2自訂tty.js服務

我們可以在根目錄建立一個mytty.js的檔案,然後輸入以下內容,

var tty = require('./lib/tty.js');
var app = tty.createServer({
  shell: 'bash',
  users: {
    foo: 'bar'
  },
  port: 8000
});

app.get('/foo', function(req, res, next) {
  res.send('bar');
});

app.listen();

在tty.createServer()中自訂tty服務,其中shell設定了啟動的終端程式,users設定了訪問web網頁時的認證使用者資訊,port設定了服務監聽連接埠號碼。儲存檔案,然後運行下面命令,

$ node mytty.js

然後在瀏覽器中輸入http://127.0.0.1:8000/,會彈出輸入使用者名稱和密碼的輸入框,輸入foo和bar,然後便可以開啟tty服務的網頁。

3.3 tty服務的設定檔

tty.js服務的設定檔在~/.tty.js/config.json,該檔案以json的格式儲存相關的配置。一個配置範例如下所示, 

{
  "users": {
    "hello": "world"
  },
  "https": {
    "key": "./server.key",
    "cert": "./server.crt"
  },
  "port": 8080,
  "hostname": "127.0.0.1",
  "shell": "bash",
  "static": "./static",
  "limitGlobal": 10000,
  "limitPerUser": 1000,
  "localOnly": false,
  "cwd": ".",
  "syncSession": false,
  "sessionTimeout": 600000,
  "log": true,
  "io": { "log": false },
  "debug": false,
  "term": {
    "termName": "xterm",
    "geometry": [80, 24],
    "scrollback": 1000,
    "visualBell": false,
    "popOnBell": false,
    "cursorBlink": false,
    "screenKeys": false,
    "colors": [
      "#2e3436",
      "#cc0000",
      "#4e9a06",
      "#c4a000",
      "#3465a4",
      "#75507b",
      "#06989a",
      "#d3d7cf",
      "#555753",
      "#ef2929",
      "#8ae234",
      "#fce94f",
      "#729fcf",
      "#ad7fa8",
      "#34e2e2",
      "#eeeeec"
    ]
  }
}

 

3.4 以https協議啟動服務

我們在~/.tty.js目錄下運行openssl命令來自己產生一個ssl的認證,

 $ openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 30000 -nodes

 

然後在~/tty.js目錄下便產生了兩個檔案cert.pem和key.pem。然後修改將上面的設定檔範例拷貝到~/tty.js/config.json中,然後修改https的配置(如所示),

然後運行bin/tty.js,

然後在瀏覽器中輸入https://127.0.0.1:8080/,瀏覽器會提示說這是一個有風險的網站,繼續訪問即可。

 (done)

本文永久更新連結地址:

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.