Ubuntu 17, right? Are you sure you are actually running Xorg, and not Wayland? (i.e. does
ps auxfww actually shows a program called
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:
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:
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).