This tutorial aims to guide you through running several X applications, disconnecting from them whilst they carry on running, and reconnecting to them. It contains a couple of tweaks to commands that workaround problems that I found when using Xpra on my Ubuntu 22.04 desktop. I thank the Xpra developer, Antoine Martin, for his assistance.
This tutorial assumes that:
- You’ve already installed Xpra from the official sources (not your distro’s built-in repos) on both the server and your PC.
- You can SSH into the server from your PC.
- Your server has Xeyes and Xterm installed.
If your organisation’s Cyber Security team allow you to use SSH public keys to login to the server, ssh-copy-id user@server will minimise the typing of your password.
Steps
Starting Xeyes
1. SSH into the server and type:
xpra seamless --start=xeyes
You can’t see an Xeyes window yet, by design. Xeyes has started on the server but you don’t yet have a means of seeing it. Press enter to get a prompt and then press CTRL-D to logout from the server.
2. On your PC in a terminal window, type:
xpra attach ssh://user@server
Xeyes opens on your screen, even though you logged out of the server.
3. Right-click the Xpra icon in your system tray and choose Disconnect, and Xeyes will close again. Don’t click the “close” on the Xeyes window itself. Repeat step 2 to satisfy yourself that Xpra is keeping Xeyes open for you on the server.
Running two X programs at once
4. SSH back into the server and type:
xpra seamless --start xterm
Note that the output includes:
Actual display used: :2
The number shown may differ for you. Xpra has selected an available virtual display for you automatically.
5. On your PC in a terminal window, type:
xpra attach ssh://user@server/
No windows open and you see in the terminal output:
there are multiple servers running,
please specify.
You can see the list using `xpra list`
Xpra is helpfully telling you that it doesn’t know which of the two X applications you want to use. Instead, type:
xpra attach ssh://user@server/2
Xterm opens on your PC screen. The “2” is the number that was displayed to you when you started Xterm in Xpra.
Listing and ending Xpra sessions
6. On the server, see all your sessions by typing:
xpra list
Note: this doesn’t tell you what commands the sessions are running. It will, however let you see whether sessions carried on after you finished using a program.
7. To end my Xterm and Xeyes sessions, I type on the server:
xpra stop 2
xpra stop
Note that, like xpra attach, xpra stop needs to be given a virtual display number to act on if there is more than one session running.
If I was still connected to Xterm and Xeyes from my PC, the Xpra clients automatically closed.
Hints
- If you close the X application using its close button or any other built-in exit feature, the Xpra session carries on running even though the X application is closed. Use
xpra stopto end the stale session. xpra listcannot tell you the name of the application that a given session is running, so when you launch an application, jot down the number of the virtual display it uses.
Troubleshooting
I spent a lot of time and questioning of M. Martin to find out that the Paramiko libraries seem to read the SSH username from your ~/.ssh/config file, even if you give a username in the Xpra command. If you get a modal dialog prompting you for the password for a username@host different from the one you gave on the command line, either pass --ssh=ssh to Xpra or edit your ~/.ssh/config.