x11 forwarding fails with some apps opening in remote display and some in local display

I have mac with xquartz as a remote client for X11 on my latest ubuntu linux. I am able to connect with ssh and start applications like xclock remotely. With most of the apps like gnome-calculator the app opens in ubuntu local display instead of remote display as intended. SSH configuration should be fine and to my best understanding this has something to do with display parameter in x11 forwarding. Any help will be appreciated.

3 Answers

I had the same problem with ssh -X user@remote. Some applications are showing on local side (e.g. xclock), and some on the remote side (e.g. gedit). I believe this is a problem is with all GTK/Gnome applications. It only happened when a remote display was running (I was using NoMachine at the same time)

I found a workaround: unset XDG_RUNTIME_DIR environment variable.

ssh -X -C user@remote
unset XDG_RUNTIME_DIR
gnome-calculator

The same effect is by using su - $USER. The - is important here

ssh -X -C user@remote
su - $USER
gnome-calculator

Now application shows on local display always, even when a remote desktop is opened.

4

Apparently sudo app_name helped. For some reason without sudo the application starts as local instead of remote display. Apparently same user can't be logged in from console same time as remote X connection starts application or it will launch the application in console.

1

I've read the three posts here, and I think there is a little misunderstanding of the -X option.

The intention of the -X option of the ssh client is to forward a remote display to a local one thus you can run remote resources and view them locally... for more information read man ssh.

When you are using sudo or su these commands just break the normal work of the X-forwarding, thus the GUI applications are running on the remote display. Something more when you are using sudo some-gui-app it breaks the ownership of the files in your $HOME directory, which could cause some issues - the fix is: sudo chown -R $USER:USER $HOME, and next time use sudo -i ... or sudo -H ....

In order to run a GUI application on the remote display from within ssh session, you need to export the values $DISPLAY and $XAUTHORIT (and in some cases some other variables) of the desktop session where you want to run the application - normally this is the active session, where the user is logged-in and the session is displayed on the physical screen.

Time ago, I've developed a bash script that is able to detect the active desktop session and export all its variables from within the current session (ssh|cron|tty|etc.). Initially I needed to solve similar task for crontab, this is the reason of the original name of the script cron-gui-launcher, but it has a wider field of usage. The script, all necessary explanations, and couple of example of usage are available within my GitHub's repository: .

Here is a video demonstration how the script works: Ubuntu: CRON GUI Launcher Demo - SSH.

2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like