9

I have not found this exact question but I could be using incorrect terms. In Ubuntu 16.04 I was able to start graphical applications over SSH by first running:

export DISPLAY=0.0

then any graphical program will open when launched in the same SSH session.

For example nohup sudo -u $LOCALUSER gedit & will open up gedit for the local user to use.

I am aware that the switch from the aging X11 to Wayland is the reason this no longer works.

What would be the current way to do this in 17.10/Wayland? Most of my workstations are managed remotely for local operators with limited access. A one liner solution for this would be desirable. We cannot do any complicated modifications from the initial install. The lack of information makes me think this is not possible in the default install, and requires system modification. Is a "one liner" on a default system possible to allow launching of GUI applications via SSH?

If not possible, we can wait until this update is made before upgrading.

Yaron
  • 13,453

2 Answers2

5

X11 is way old tech at this point. To do this with wayland, check in a GNOME Terminal window:

$ echo $DISPLAY $XAUTHORITY
:0 /run/user/1000/gdm/Xauthority

In the ssh session, define those two values:

XAUTHORITY=/run/user/1000/gdm/Xauthority DISPLAY=:0 gedit

Verified to work on Ubuntu 19.04.

David Foerster
  • 36,890
  • 56
  • 97
  • 151
0

I found that if you ssh as the same user which is logged in on the graphical session, graphical programs can be started without any additional steps.

If you instead ssh as root or a different user, some environment variables need to be set up.

It already works if you just set XDG_RUNTIME_DIR:

XDG_RUNTIME_DIR="/run/user/$(id -u demouser)" runuser -u demouser -- gedit

However, this shows warning messages, because some environment variables are missing. We can get a more complete environment with systemctl --user show-environment.

To use this, we can create a small wrapper script, which runs a command with these environment variables. Let's call it /usr/local/bin/env-wrapper.

#!/bin/bash
set -o allexport
XDG_RUNTIME_DIR="/run/user/$(id -u)"
eval "$(systemctl --user show-environment)"
exec "$@"

We can then use it like this:

runuser -u demouser -- /usr/local/bin/env-wrapper gedit