Skip to content

Remote access with SSH

mviereck edited this page Feb 12, 2022 · 12 revisions

SSH X forwarding

You can run x11docker on remote servers with ssh -X like a regular X application. Example:

# Replace localhost with address of your desired server

ssh -X localhost -- x11docker x11docker/lxde lxterminal

If your server has e.g. Xephyr or nxagent installed, you can run desktop environments like a VNC session:

ssh -X localhost -- x11docker --desktop x11docker/lxde

It is recommended to provide a nested X server like nxagent on the remote machine to allow x11docker circumventing X security leaks.

SSH with xpra

SSH setup with xpra allows detaching and reattaching to a remote session.

Example for an SSH setup with xpra:

  • Server setup:
#! /bin/bash

# Run invisible Xvfb X server with display number :30.
# Catches X environment with 'read < <(...)' construct.
# Docker container runs on invisible Xvfb display.
# (for X server options other than --xvfb or --xdummy also add options --showenv and --xtest).

read Xenv < <(x11docker --xvfb --printenv --display=30 x11docker/lxde pcmanfm)

# Output of new X environment, just for info
# (You can drop `--display=30` in command above if you provide DISPLAY
# from this output to following xpra commands instead of :30)

echo $Xenv

# Start xpra server with new environment variables.
# (Replace "start" with "start-desktop" to forward a desktop environment)

env $Xenv xpra start :30 --use-display --start-via-proxy=no --daemon=no
  • Client setup:
# Attach xpra client over SSH to xpra server.
# Replace SERVERIP with IP or host name of ssh server.
# You might need to specify a user name in the form USER@SERVERIP

xpra attach ssh:https://SERVERIP/30

You can detach the SSH connection and attach later again without terminating the container application:

xpra detach ssh:https://SERVERIP/30

You can stop xpra server without terminating x11docker:

xpra stop ssh:https://SERVERIP/30

SSH with xpra, second example

A script entirely executed on client. (It will ask three times for ssh password, may be solved more nicely).

#! /bin/bash

HOSTNAME=localhost                         # Change to desired server address
IMAGECOMMAND="x11docker/lxde lxterminal"   # Change to desired image name and command

# Runs x11docker on remote server. Reads new X environment variables from its output.
# (for X server options other than --xvfb or --xdummy add options --showenv --xtest).
read Xenv < <(ssh -f $HOSTNAME -- x11docker --xvfb --printenv $IMAGECOMMAND)

# extract DISPLAY from new X environment
Newdisplay=$(sh -c "export $Xenv ; echo \$DISPLAY")

# start remote xpra server
# (replace "xpra start" with "xpra start-desktop" for desktop environments)
ssh $HOSTNAME -- env $Xenv xpra start $Newdisplay --use-display --start-via-proxy=no

# start local xpra client
xpra attach ssh:https://$HOSTNAME/$Newdisplay

SSH with xpra, annotations

  • If you have xpra version <2.4, don't try this on localhost due to an xpra memory bug.
  • If your client does have a big display resolution or a multimonitor setup, xpra may scale up the size of forwarded windows. Check output of xrandr | grep current or xpra client output for your client display resolution. It may be e.g. 2084x768. Add --size 2048x768 to x11docker --xvfb [...] command to get a matching server display size.
Clone this wiki locally