Linux remote login

Posted by André on 2015-03-01.

For really a long time I have used a really nice feature of the X11 windowing system - remote login. That was rather easy to do. Just enable XDMCP and connecto to the X server remotely. It was not safe over the networks, but I used it only locally. My main use case was and is using the main PC in my home office from other places.

Now for a few releases the Linux distributions started to disable the protocol, or at least make it more complicated to use, as XDMCP isn't supported in the admin tools anymore.

Remote desktop is generally supported via the VNC protocol. VNC has an advantage in that it allows connecting to a running server, keeping sessions alive between connects and even share screens with multiple clients (as far as I understand).

But old habits die hard, and I rather prefer running X over SSH forwarding (using the simple "-X" option to the ssh command). However, remoting the whole desktop is still difficult, because you need a full local X server to display the window manager etc. I struggled to find a real solution to this, e.g. with the Xnest nested X server (run an X server in a window of another X server).

However, I have now found a nice and rather easy solution using the Xephyr X server, which is Xnest plus support for compositing and all. Simply run the script shown here to login to a remote server via SSH and display the KDE (default, but you can change it) window manager:

#!/bin/sh

USERATHOST="$1"

WINMGR="startkde"
if [ $# -gt 1 ]; then
	WINMGR="$2"
fi;

KBDOPTS="-keybd ephyr,,,xkbmodel=evdev,xkblayout=de"

if [ "x$USERATHOST" = "x" ]; then
	echo "Remote graphical login via ssh X11 forwarding"
	echo "Usage:"
	echo "  $0 <user@host> [<window manager>]"
	exit 1;
fi;

Xephyr -screen 1900x982 -resizeable ${KBDOPTS} :1 &

# wait till Xephyr logs are done and we can see the ssh login
sleep 3;

DISPLAY=:1.0 ssh -XfC -c blowfish "${USERATHOST}" "${WINMGR}"

Using this script I am finally able to work remotely, do my mail, and more. I am even writing this blog entry "remotely". I can even run a virtual machine on the remote machine, and display its screen remotely! (I know I should directly SSH into the virtual machine, but haven't gotten to set this up).

I only wonder how long this will still work with the advent of the wayland compositors. Without a decent remoting solution that would really be a step back in the linux world.

(Of course, code AS IS and without any warranty)

Edit: remove the "f" option from ssh when you want to run it in an xterm, as when ssh goes to the background because of the "-f" option, xterm terminates - but seems to take ssh with it. Which then may give the "Could not start ksmserver" error message...

Edit Sept. 2016: remove the "-c blowfish", as this only works for SSH v1. Just let SSH decide which cipher to use.