Skip to content

Remote access with SSH

mviereck edited this page Sep 20, 2018 · 12 revisions

SSH X forwarding

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

SSH with xpra

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

Example for an SSH setup with xpra:

  • Server setup:
# run invisible Xvfb X server with display number :30.
# catch X environment with 'read < <(...)' construct.
# docker container runs on invisible new display.
read Xenv < <(x11docker --xvfb --display=30 --showenv x11docker/lxde pcmanfm)

# 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
  • Client setup:
# Attach xpra client over SSH to xpra server
xpra attach ssh:$HOSTNAME:30     # replace $HOSTNAME with IP or host name of ssh server

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

xpra detach ssh:$HOSTNAME:30

You can stop xpra server without terminating x11docker:

xpra stop ssh:$HOSTNAME: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.
read Xenv < <(ssh -f $HOSTNAME -- x11docker --xvfb --showenv $IMAGECOMMAND)
# extracts display from new X environment
Newdisplay=$(sh -c "export $Xenv ; echo \$DISPLAY")
# start remote xpra server
ssh $HOSTNAME -- env $Xenv xpra start $Newdisplay --use-display --start-via-proxy=no
# start local xpra client
xpra attach ssh:$HOSTNAME$Newdisplay

Annotations

  • Warning: don't try this on localhost due to an xpra memory bug in xpra versions <v2.4.
  • 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