I had the same issue with Ubuntu 17.10. It could be that my system was not properly configured. Anyway, in my case, I added
xhost + SI:localuser:root > /dev/null
at the bottom of my ~/.bashrc
file and it worked. I don't know if this is a security risk. I share that in case someone else is in the same situation and trust that adding root to the list of privileged X server users should be OK.
It is suggested here on ubuntuhandbook.org
You can test it directly on the terminal first:
xhost + SI:localuser:root
xhost -
The second line makes sure that only those in the list have access to the X server. Then try "Edit as administrator", after right clicking on a file or directly execute
pkexec gedit
If this does not work, then it is pointless to make the command permanent in ~/.bashrc
.
To be more precise, I first executed
xhost
to see which users had access to the X server. I saw that the format was SI:localuser:dominic
where dominic
is my login name. So, I used the same format SI:localuser:root
to add the root
user.