X11 authentication problem

Hi there, this is a follow-up to

I cannot start GUI snap applications remotely. One writes:

Unable to init server: Could not connect: Connection refused
Fatal error: exception Gtk.Error("GtkMain.init: initialization failed\nml_gtk_init: initialization failed")

another says:

X11 connection rejected because of wrong authentication.

The above linked snapcraft forum article suggests to set XAUTHORITY and linking $HOME/.Xauthority from /snap/myapp/current, but neither helped.

What should I do to make it work?

What are you doing to stop it working? This works for me:

ssh -X octopull-x1c3-22-10 "sh -lc 'XAUTHORITY=~/.Xauthority ubuntu-frame'"

I ssh -X into the remote machine and there I start

$ /snap/bin/myapp

apt-installed X apps do work remotely.

What is “ubuntu-frame” in the above command?

Now I see. It is the GUI application. I tried it with my one and told me te first error message above again.

ubuntu-frame is a snap that I happen to have installed.

It looks like you are not setting XAUTHORITY to “~/.Xauthority” when launching the snap.

I have put an

export XAUTHORITY=/home/user/.Xauthority

line into my .bashrc, ran it. Now starting

/snap/bin/myapp

resulted in a longer wait than usual, but got the same error message as before:

Unable to init server: Could not connect: Connection refused
Fatal error: exception Gtk.Error("GtkMain.init: initialization failed\nml_gtk_init: initialization failed")

For non-snap applications my .Xauthority file works. Should I re-generate it somehow?

Interestingly, gimp did start now, but not myapp.

Try my snap. If that works, then the problem is your snap.

OK, so other snaps work and yours doesn’t. You’ll have to work out what is different

This seems to be something GTK-specific, or how my application was packaged in snap. I go with my investigations in that direction.

GTK apps (e.g. Gimp) don’t have a problem running on X11: I suggest you investigate your packaging first