AWS EC2 Ubuntu 18.04 LTS and export $DISPLAY to run graphical application

0

If I SSH into a Raspberry Pi or into a local VM running Ubuntu 18.04 LTS, then I can run:

user:~$ export DISPLAY=:0
user:~$ gedit

And this will open a graphical window on the OS with the text editor, gedit. However, if I SSH into an AWS EC2 instance running Ubuntu 18.04 LTS, and I run "export DISPLAY=:0" followed by "gedit", I get these errors:

No protocol specified
Unable to init server: Could not connect: Connection refused

(gedit:<proces id>): Gtk-WARNING **: <time stamp>: cannot open display: :0

Is there any way to find the display number, or any other way to launch a graphical application? Note that I do not want to forward a GUI window back to my terminal by passing for instance the -X flag.

mikorym

Posted 2019-10-02T06:57:25.833

Reputation: 1

Where do you want this gedit instance to display its window? – Kenster – 2019-10-02T12:29:57.000

Answers

0

Make the graphical session write its display number somewhere at login time.

For example, put these in your ~/.Xprofile:

echo "$DISPLAY" > ~/tmp/current-display
echo "$XAUTHORITY" > ~/tmp/current-xauthority

To make sure everything works, you should also repeat this with $DBUS_SESSION_BUS_ADDRESS and $XDG_RUNTIME_DIR, although they are frequently static on systemd-based systems, but not always.

Later you will be able to run:

export DISPLAY=$(< ~/tmp/current-display)
export XAUTHORITY=$(< ~/tmp/current-xauthority)

Note that No protocol specified frequently means that the display number was correct but that it denied the connection due to missing Xauth data.

user1686

Posted 2019-10-02T06:57:25.833

Reputation: 283 655

I created ~/.Xprofile with those two lines and the directory ~/tmp, but at login no files get written to ~/tmp. There is a file .Xauthority with magic cookie data. – mikorym – 2019-10-02T07:38:20.333