星期日, 2月 25, 2018

tmate with openSUSE Leap 42.3

tmate with openSUSE Leap 42.3
使用 tmate 即時分享終端機

OS:  openSUSE Leap 42.3 in Azure

之前在社群舉辦活動的時候, 使用 OBS Studio ( https://obsproject.com/  ) 來進行活動直播
那個時候就有思考, 如何即時分享講者的終端機操作

那個時候找到 tmate 這個軟體
  • 官方網站 https://tmate.io/
  • 可以即時以 SSH 或是 Web 方式分享終端機
  • 可以指定 Read-only 方式連線 SSH 或是 Web終端機

首先搜尋套件 tmate

# zypper  search   tmate
Loading repository data...
Reading installed packages...

S | Name  | Summary                  | Type   
--+-------+--------------------------+--------
 | tmate | Instant terminal sharing | package

安裝 tmate 套件

# zypper  install  tmate
Loading repository data...
Reading installed packages...
Resolving package dependencies...

The following 3 NEW packages are going to be installed:
 libmsgpackc2 libssh4 tmate

3 new packages to install.
Overall download size: 412.6 KiB. Already cached: 0 B. After the operation, additional 1.0 MiB will be used.
Continue? [y/n/...? shows all options] (y): y

因為 tmate 是透過 ssh 跟官網那邊進行連線, 所以要先建立 SSH 金鑰
先觀察目錄

# ls -a  ~
.  ..  .bash_history  .gnupg  bin

用 ssh-keygen 指令建立 SSH 金鑰
預設放在家目錄 ~/.ssh 目錄內 , 這邊是以 DSA 為例

# ssh-keygen  -t  dsa
Generating public/private dsa key pair.
Enter file in which to save the key (/root/.ssh/id_dsa):
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_dsa.
Your public key has been saved in /root/.ssh/id_dsa.pub.
The key fingerprint is:
SHA256:exF8nA9WJ+arFCxZitM73rlJhv8zSLwozlFrFQyAnZ8 root@test01
The key's randomart image is:
+---[DSA 1024]----+
|       o.o. . + .|
|      . o+ O = o |
|        o.B.@ .  |
|         .E* = . |
|        S =.o o  |
|         + Ooo   |
|        o *o*o   |
|       ..+.+ooo  |
|       .o.  +..o |
+----[SHA256]-----+


再次觀察目錄

# ls  -a  ~/.ssh
.  ..  id_dsa  id_dsa.pub


執行 tmate 指令啟動 tmate
# tmate

這個時候其實可以觀察 /tmp 目錄
底下應該有 tmate相關目錄

# ls   /tmp/
.ICE-unix  .Test-unix  .X11-unix  .XIM-unix  .font-unix  tmate-0

如果有在執行tmate的時候, 該目錄底下會有 socket 檔案
# ls -l   /tmp/tmate-0/
total 0
srwxrwx--- 1 root root 0 Feb 25 07:37 bm33KG

使用 tmate  show-messates 顯示連線相關資訊

# tmate  show-messages
Sun Feb 25 06:40:13 2018 [tmate] Connecting to ssh.tmate.io...
Sun Feb 25 06:40:13 2018 [tmate] Note: clear your terminal before sharing readonly access
Sun Feb 25 06:40:13 2018 [tmate] web session read only: https://tmate.io/t/ro-x0iPdPMpfkFxXa8UPQmLUnPEH
Sun Feb 25 06:40:13 2018 [tmate] ssh session read only: ssh ro-x0iPdPMpfkFxXa8UPQmLUnPEH@ny2.tmate.io
Sun Feb 25 06:40:13 2018 [tmate] web session: https://tmate.io/t/H7FQW5vPlqKEVnCUMXKnSd2QS
Sun Feb 25 06:40:13 2018 [tmate] ssh session: ssh H7FQW5vPlqKEVnCUMXKnSd2QS@ny2.tmate.io

分享之前記得清畫面 :p

這邊會看到有分 web session read only, web session還有 ssh session read only 以及 ssh session.

差異只在是否可以操作指令

Web session 部份只要在瀏覽器開啟連結就好
例如


SSH Session 部份也是在終端機按照連結連線即可

先記下來

~ enjoy it


Reference:



沒有留言: