Xpra over SSH from Ubuntu 22.04

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 stop to end the stale session.
  • xpra list cannot 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.

Safely installing Python applications and managing additional Python versions

NUIT sometimes see University Ubuntu systems where the graphical desktop is missing because the colleague or student has attempted to remove the system Python, some of the system’s essential Python libraries and applications, or both. Other times, we see system applications, such as the Software Updater and the ubuntu-drivers driver selection tool, not working properly because the colleague or student has installed a different Python version alongside the system Python and then set the new Python version to be the default python3 command system-wide.

This damage often leaves the system unusable, preventing the colleague or student from working. The only solution is for NUIT to reinstall the Ubuntu operating system.

What to avoid

  • Do not try to remove or replace the existing Python 3. Python is embedded into Ubuntu so heavily that an attempt to remove the python3 package will remove the Ubuntu desktop and hundreds of other packages, rendering the system unusable.
  • Do not parallel install a second Python and make it answer to python3 instead of the system Python. Redirecting the python3 command to a Python other than the one you get from apt install python3 will stop Ubuntu-specific applications and libraries from working.

Solutions

  • Pyenv allows you to install multiple Python versions into your home directory without affecting the system Python, and switch between them easily. Example: pyenv install 3.8 ; pyenv local 3.8
  • Pipx will install applications written in Python and handle their dependencies elegantly. Limitations are that optional modules that are not marked as dependencies aren’t installed and cannot trivially be added. Example: pipx install --include-deps ipykernel
  • Pip3 is needed to install Python libraries where there is no application component. You should use the --user flag with pip3. Example: pip3 install --user pysqlite3
  • Virtualenv lets you install multiple versions of the same Python application or library to cope with different projects and switch between them. Example: virtualenv myenv ; source myenv/bin/activate

Do not use sudo with any of these tools, they are all designed to be run with ordinary user privileges.

Pyenv doesn’t switch Python versions within a Virtualenv instance, but you can mimic that feature as follows: virtualenv --python ~/.pyenv/versions/3.12.1/bin/python myenv

After installing Pyenv

You need to install some dependencies and set up aliases. Read on…

Install dependencies

Pyenv needs certain libraries and development headers installed via Apt before you can use it to install Pythons:

~ $ pyenv install 3.12
Downloading Python-3.12.1.tar.xz...
-> https://www.python.org/ftp/python/3.12.1/Python-3.12.1.tar.xz
Installing Python-3.12.1...
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/campus.ncl.ac.uk/me/.pyenv/versions/3.12.1/lib/python3.12/bz2.py", line 17, in <module>
    from _bz2 import BZ2Compressor, BZ2Decompressor
ModuleNotFoundError: No module named '_bz2'
WARNING: The Python bz2 extension was not compiled. Missing the bzip2 lib?
[many lines omitted]
Installed Python-3.12.1 to /home/campus.ncl.ac.uk/me/.pyenv/versions/3.12.1

You must infer these missing dependencies from the errors that pyenv install 3.12 emits, so what you need may not match the packages listed below. apt search thing and yum search thing will be useful for this.

What I needed to install when writing this guide, to give an example of the kind of dependencies you might need:

sudo apt install libbz2-dev libncurses-dev libffi-dev \
    libreadline-dev tk-dev liblzma-dev

The same example for RedHat:

sudo yum install bzip2-devel ncurses-devel libffi-devel \
    readline-devel tk-devel lzma-devel

Remove the failed Python version before trying again:

rm -rf ~/.pyenv/versions/3.12.1

pyenv install 3.12

On Ubuntu 24.04 systems, you also need to install zlib1g-dev otherwise you get the unhelpfully-opaque:

student@labC1QBRO:~$ pyenv install 3.12
Downloading Python-3.12.5.tar.xz...
-> https://www.python.org/ftp/python/3.12.5/Python-3.12.5.tar.xz
Installing Python-3.12.5...

BUILD FAILED (Ubuntu 24.04 using python-build 20180424)

Inspect or clean up the working tree at /tmp/python-build.20240903154016.7543
Results logged to /tmp/python-build.20240903154016.7543.log

Last 10 log lines:
  File "/tmp/python-build.20240903154016.7543/Python-3.12.5/Lib/ensurepip/__init__.py", line 200, in _bootstrap
    return _run_pip([*args, *_PACKAGE_NAMES], additional_paths)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/python-build.20240903154016.7543/Python-3.12.5/Lib/ensurepip/__init__.py", line 101, in _run_pip
    return subprocess.run(cmd, check=True).returncode
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/python-build.20240903154016.7543/Python-3.12.5/Lib/subprocess.py", line 571, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['/tmp/python-build.20240903154016.7543/Python-3.12.5/python', '-W', 'ignore::DeprecationWarning', '-c', '\nimport runpy\nimport sys\nsys.path = [\'/tmp/tmpjoslp4b2/pip-24.2-py3-none-any.whl\'] + sys.path\nsys.argv[1:] = [\'install\', \'--no-cache-dir\', \'--no-index\', \'--find-links\', \'/tmp/tmpjoslp4b2\', \'--root\', \'/\', \'--upgrade\', \'pip\']\nrunpy.run_module("pip", run_name="__main__", alter_sys=True)\n']' returned non-zero exit status 1.
make: *** [Makefile:2027: install] Error 1

Set up the aliases

Pyenv gives you a Python interpreter that answers to the name python. To have it also answer to python3 and switch between the system Python and Pyenv-installed Pythons reliably, run:

sudo apt install python-is-python3

alias python3=python

Then add that alias to your shell’s run control file. The wide variety of shells in use means that we cannot give specific instructions for that.

If you don’t install python-is-python3 and don’t set up the alias, you see outcomes like:

~ $ pyenv local 3.12.1

~ $ python --version
Python 3.12.1

~ $ python3 --version
Python 3.10.12

~ $ pyenv local system  

~ $ python --version   
pyenv: python: command not found

The `python' command exists in these Python versions:
  3.12.1

Pyenv demonstration

The below demonstrates how Pyenv can be used to set up a directory for a project that needs a specific Python version without affecting the Python version used elsewhere:

~ $ pyenv global system

~ $ python3 --version  
Python 3.10.12

~ $ python --version   
Python 3.10.12

~ $ mkdir pyenv-test ; cd pyenv-test

~/pyenv-test $ pyenv local 3.12.1             

~/pyenv-test $ python3 --version               
Python 3.12.1

~/pyenv-test $ python --version               
Python 3.12.1

~/pyenv-test $ cd ..

~ $ python --version
Python 3.10.12

~ $ python3 --version
Python 3.10.12

Mapping your H drive in Ubuntu MATE desktop

Intended audience: Linux users at Newcastle University

For other operating systems, NUIT have a guide.

  1. Go to My Details and click on “Technical information, including details of which file-server you use and any role accounts you own” to get the webfolders path to your H drive.
  2. Click on the Places menu and choose Connect to server…
  3. Fill in Type = Secure WebDAV (HTTPS), Server = webfolders.ncl.ac.uk, Folder = /home/homeXX/yourusername, and your user name and password. Tick Add bookmark and type “H Drive” as your bookmark name.
  4. Check that you have filled the form in correctly and click Connect.

If you need to access the H drive from the command line or a program (e.g. Matlab outputs), it is under /var/run/user/digits/gvfs/davs:string

You might also want to use University-supplied resilient storage to back up the local home folder on your Ubuntu PC.

Comments are disabled. If there is an inaccuracy in this page or you need further help accessing your H drive from Linux, please raise a Service Desk ticket.

Backing up your GNU/Linux box’s local home folder to your H: drive

Local home folders that don’t sync to your H: drive is a known limitation of the managed Linux desktop service offered by the School of Computing. Here’s how to protect your data:

  1. Go to a cluster PC and make a folder called “backups” in your H: drive.
  2. Go back to your Linux PC.
  3. In the MATE panel, click System → Preferences → Other → Backups
  4. Make sure that “Folders to save” lists “Home (your username)”
  5. “Folders to ignore” should contain folders that you don’t need to backup, to conserve H: space. Examples include “.thunderbird” (it’s huge, mostly contains cached emails, and your email is on the Outlook server), “Downloads”, and any Git, Mercurial, or SVN repos that you routinely push or commit to a remote server.
  6. “Storage location” sets up as follows:
    • Storage location = WebDAV
    • Server = webfolders.ncl.ac.uk
    • Tick the HTTPS checkbox
    • Folder should say something like “/home/home08/ntu12/backups”, you can find out what it needs to be from tech-info.php. The end of the folder path should be “backups” so that you use H:\backups.
    • User is your campus username.
  7. Scheduling: I recommend turning on automatic scheduling, daily backups, and keeping backups for six months.
  8. Go to “Overview” and click “Back up now”. You will be asked for your campus password (to access the Home Archive drive) and a separate, optional, encryption password. If you set an encryption password that you later forget, you will not be able to restore your data. I didn’t encrypt my backups because I already trust NUIT staff with everything on my H: drive.

The backups are stored as gzip and manifest files in the backups folder. Don’t interfere with these files as you may corrupt your backups.

How to restore

To restore, you need to go to System → Preferences → Other → Backups as above and use the restore button. In Ubuntu 16.04, MATE also allows you to right-click in a Caja window and choose Restore missing files.

Under the bonnet

If you are using one of the managed desktops that we support, all the software you need to run backups is already installed. If you want to do this from an unmanaged machine or a managed laptop, you need to install “deja-dup”, “duplicity”, and the “topmenu-gtk” packages needed by your desktop environment. If you want to use the command line, you can run duplicity directly. Duplicity has an extensive man page.

Comments are disabled. If there is an inaccuracy in this page or you need further help with using your H drive from Linux, please raise a Service Desk ticket. Previous versions of this page referred to the Home Archive service, which has now been retired.

Installing Ubuntu 16.04 on Lenovo Thinkpad T440p

Intended audience: Thinkpad owners who are considering Ubuntu 16.04.

We couldn’t get Ubuntu to install successfully in UEFI mode at all, never mind with Secure Boot. The installation would finish, we would reboot, and the computer wouldn’t find an OS. The only way around was to disable UEFI:

  • Go into the BIOS at boot time.
  • Startup → UEFI/legacy boot and choose legacy only.

Installing Ubuntu 16.04 on Dell XPS 9350

Intended audience: XPS owners who are considering Ubuntu 16.04.

BIOS/UEFI settings

Press F2 at POST.

  • Go into Settings → System configuration → SATA Operation and choose Disabled. This is required for the OS to even see the SSD.
  • I was able to set up Ubuntu 16.04 with Secure Boot enabled.

Quirks

  • For the USB-C/Thunderbolt network adaptor to work, it must be plugged in before boot and left plugged in. If you plug it in after boot, or unplug it and replug it after boot, the adaptor is not detected and nothing is shown in journalctl. The only workaround known to me is to reboot, as nothing in the BIOS seemed to affect this behaviour.
  • The SSD is listed as nvme0n1 and the partitions as nvme0n1p1 etc. nvme0 appears to be what the Linux kernel calls the disk controller.