{"version": "https://jsonfeed.org/version/1", "title": "/dev/posts/ - Tag index - screen", "home_page_url": "https://www.gabriel.urdhr.fr", "feed_url": "/tags/screen/feed.json", "items": [{"id": "http://www.gabriel.urdhr.fr/2016/10/18/terminal-sharing/", "title": "Terminal read-only live sharing", "url": "https://www.gabriel.urdhr.fr/2016/10/18/terminal-sharing/", "date_published": "2016-10-18T00:00:00+02:00", "date_modified": "2017-05-06T00:00:00+02:00", "tags": ["computer", "unix", "ssh", "screen"], "content_html": "
Live sharing a terminal session to another (shared) host over SSH in\nread-only mode.
\nUpdate: 2017-05-06 add broadcastting over the web with\nnode-webterm
#!/bin/sh\n\nhost=\"$1\"\n\nfile=script.log\ntouch \"$file\"\ntail -f $file | ssh $host 'cat > script.log' &\nscript -f \"$file\"\nkill %1\nssh $host \"rm $file\"\nrm \"$file\"\n
\nscreen
screen
can save the content of the screen session on a file. This is\nenabled with the following screen
commands:
logfile screen.log\nlogfile flush 0\nlog on\n
\nThe logfile flush 0
command removes the buffering delay in screen
\nin order to reduce the latency.
We can watch the session locally (from another terminal) with:
\ntail -f screen.log\n
\nThis might produce some garbage if the original and target terminals are not\ncompatible (echo $TERM
is different) or if the terminal sizes are different:
screen
;xterm -geometry 90x40
, xfce4-terminal --geometry 90x40
, etc.).Instead of watching it locally, we want to send the content to another (shared)\nhost over SSH:
\ntail -f screen.log | ssh $server 'cat > /tmp/logfile'\n
\nOther users can now watch the session on the remote host with:
\ntail -f screen.log\n
\nxterm
You can create a log file from xterm
:
xterm -l -lf xterm.log\n
\nThe rest of the technique applies the same.
\nBest viewed from a xterm
-compatible terminal.
script
script
can be used to create a log file as well:
script -f script.log\n
\nThe downside is that a log file is created on both the local and server-side.\nThis file might grow (especially if you broadcast\nnyancat
\ud83d\ude3a for a long time)\nand might need to be cleaned up afterwards.
A FIFO might be used instead of a log file with some programs. It\nworks with screen
and script
but not with xterm
. However, I\nexperienced quite a few broken pipes (and associated brokeness) when\ntrying to use this method. Moreover, using a FIFO can probably stall\nsome terminals if the consumer does not consume the data fast enough.
In order to avoid the remote log file, a solution is to setup a terminal\nbroadcast service. A local terminal broadcast service can be set up with:
\nsocat UNIX-LISTEN:script.socket,fork SYSTEM:'tail -f script.log'\n
\nAnd we can watch it with:
\nsocat STDIO UNIX-CONNECT:script.socket\n
\nWe can expose this service to a remote host over SSH:
\nssh $server -R script.socket:script.socket -N\n
\nThe downside of this approach is that the content is transfered over\nSSH once per viewer instead of only once.
\nnode-webterm
can be used to\nbroadcast the log over HTTP:
{\n\t\"login\": \"tail -f script.log\",\n\t\"port\": 3000,\n\t\"interface\": \"127.0.0.1\",\n\t\"input\": true\n}\n
\nThis displays the terminal in the browser using\nterminal.js
, a JavaScript\nxterm
-compatible terminal emulator (executing client-side).\nThe default terminal size is the same as the default xterm
size.\nIt can be configured in index.html
.