Missing ~/.Xauthority file in Ubuntu 17.10 [duplicate]

In Ubuntu 17.10, when I log in using Wayland and try to run a GUI app using root access it says

unable to copy the user's xauthorization file

I tried

sudo chown sharif:sharif ~/.Xauthority

but the result was

chown: cannot access '/home/sharif/.Xauthority': No such file or directory

But in Xorg those apps run well.


Solution 1:

Check out https://bugs.launchpad.net/ubuntu/+source/synaptic/+bug/1551951, with a workaround in comment #9. In particular:

The method pkexec uses to grant root (i.e. the user it runs its argument as) access to the real user's X display doesn't work under Wayland, but still using X (i.e. using Xwayland). Xwayland (at least as started by mutter/gnome-shell) is started without the "-auth" option and hence only grants access to the real user (adopting Wayland's security model). Hence there's no Xauthority file to grant access to other users. The workaround is to explicitly allow root to access the user's X display using

$ xhost +si:localuser:root

I just tried this on my installation of Artful and synaptic finally ran successfully. Gparted put up a bit of a fight but also ran successfully on the second try.

The solution above works on a per-session basis. Comment #13 in that thread shows how to make it stick each time you sign in.

Solution 2:

17.10 uses wayland by default, not x11; thus, there is not an .xauthority file.

Also by default, root is not allowed access to your terminal; thus, can not run GUI programs.