Ubuntu 17, right? Are you sure you are actually running Xorg, and not Wayland? (i.e. does ps auxfww
actually shows a program called X
running?)
If you are running Wayland-- which you would be by default: accessing the display from root user is not allowed due to a security feature (cough)(cough). They said you could work around by running this command before attempting to run gksu:
xhost si:localuser:root
Another way is to just start your Ubuntu system with conventional Xorg display system; you can set this at login, I think.
I never used Ubuntu 17 though, and definitely not a Wayland user. This is probably one of the reasons that Ubuntu 18/LTS will go back to use classic Xorg by default.
Important note: If otherusername of yours is not root, no matter that you're using Wayland or classic Xorg, you need to run following command before running your program via gksu:
xhost si:localuser:otherusername
UPDATE:
The above solution is not working for Ubuntu 17.04 Xorg out of the box:
$ xhost si:localuser:root
localuser:root being added to access control list
X Error of failed request: BadValue (integer parameter out of range for operation)
Major opcode of failed request: 109 (X_ChangeHosts)
Value in failed request: 0xe
Serial number of failed request: 7
Current serial number in output stream: 9
It looks like that Ubuntu Xorg "server is not built with SECURE_RPC support, so attempting to add a FamilyNetname (0xfe) host fails."
So no out of the box solution for Ubuntu yet (but this remains as the answer until a working one exist).
What kind of X authorization does your distribution use (read up on
xauth
)? You must authorize the "other use" to use the display of the "first user". – dirkt – 2018-01-02T08:49:51.657Yes I use
xauth
, and no, I don't know how to authorize the "other use" to use the display of the "first user", please help @dirkt, that must be the missing piece to the answer. Thx! – xpt – 2018-01-02T13:52:50.533