Sudo gedit error

I open a terminal and enter “sudo gedit”, then enter my password and I get:

no protocol specified
Unable to init server: Could not connect: Connection refused

Any idea what is wrong? A workaround would be any other command that would allow me to edit admin-only files.

By default you can’t run a graphic server as root, you can edit the file by terminal with nano, vim, emacs… or let root user run windows with something like this xhost +SI:localuser:root you should do this every system restart, I usually try to use the first option, is safest and fastest.

PS: nano is the easiest editor, to save the file press ctrl+o and enter, to exit crtl+x.

3 Likes

nano is simple. That allowed me to edit an apparmor config file. Thank you very much.

hi there! :slight_smile:

it works for me on ubuntu mate, both with gedit and pluma (gedit fork). mayb u can try to start the filemanager with sudo (nautilus, or the mate fork is caja). or u can try gksudo, however theres a new alternative for gksudo, called polkit. btw what about trying to start it without sudo from terminal, or copy ur user settings to root’s home folder, or delete/rename the existing ones from there? mayb duckduckgo can give u the right answer by the error message… btw caja have a feature, that u can right click in a file browser window, and there u can find something like as open as administrator (try it on a file, and on an empty space as well…) mayb this is an extension that is available for nautilus as well… mayb u can try to reinstall it, or in final case, purge and reinstall… (dont forget about backups, and if u have everything in a safe place, then ur free to experimenting around…)

i think these can be more than enough to find any solution, so good luck, and have fun! :slight_smile: