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,173
  • 5
    The easiest way to do this would be to disable the Wayland session, and force X11 (which will be the default in 18.04) – Charles Green Feb 13 '18 at 21:18
  • Very much agreed the lowest friction solution is to disable Wayland. – Pretorious Feb 13 '18 at 21:30
  • I would have marked the question as a duplicate, but what you asked really was quite different. – Charles Green Feb 13 '18 at 21:32
  • However another team on the project is very excited about Wayland (not sure why), so I have been asked to make this happen /without/ disabling it. I understand this is an odd request and maybe outside of the scope of Wayland... or maybe my understanding of what it is has been incorrect. – Pretorious Feb 13 '18 at 21:33
  • 1
    Eh - I cannot say, obviously. I have been told Wayland is 'faster lighter betterer and will butter the bread' but the reality seems to be that the tools people use to run their computers are not quite present in the Ubuntu implementation of Wayland, yet. https://insights.ubuntu.com/2018/01/26/bionic-beaver-18-04-lts-to-use-xorg-by-default/ – Charles Green Feb 13 '18 at 21:36
  • You wish to start the GUI applications locally on the system you're connecting to, rather than forward the application to your display over ssh? (It's not quite clear in reading your question which you want exactly). Also, 17.04 (you mentioned it in the body of your question, and tagged with it, but title says 17.10), is end of life, and you shouldn't be using it. – dobey Feb 13 '18 at 21:45
  • Edited to 17.10 and for clarity. Yep, I want to open it locally on the machine I am connecting to. At current I use "nohup sudo - u $LOCALUSER $COMMAND &" to ensure the operator has access to the application. There are probably better way to do this, but I am at the whim of other people. – Pretorious Feb 13 '18 at 23:57

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,264
  • 56
  • 94
  • 147
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