The solution for you would be to simply use
gnomesu instead of
sudo. As written here,
it is a normal security issue. You have a multi user system where many users can login, either local or remote, in a GUI session. What if other logged in people would be able to open windows on your desktop without your allowance? Inconvenient at least, but the would also be able to create a window such that thay could read all your keyboard typing including your bank accounts. Thus the need for giving allowance with
There are multiple ways to achieve this, however this is the most simple way so I'd suggest you doing this. If you want to use the normal sudo(for I don't know what reason) anyway, you can do a change stated in this question.
xhost +localhost in your terminal, and then running the
sudo again. This lets all users on your system (i.e. root) open
windows on your screen. Make sure to use
+localhost and not simply
as it's more secure to allow connections from only localhost than from
To make this permanent, edit the ~/.xinitrc file like this:
Edit the file to look like this (it should be empty at the start):
xhost +localhost &
Now save the file, log out and log in. Now everything should run just fine with sudo.