If I try to use sudo kate
to edit a system file, I get the message:
Executing Kate as root is not possible.
So how can I edit a system file?
I put up this question so that I could answer it myself. As far as I can tell, none of the suggestions involving gksudo have any advantage over the solution I proposed: just edit the file as a non-root user, save it when you're done, and provide the root password at that time.
Just go ahead and edit the file without the
sudo
. When you're done, save it as usual. You'll get a prompt asking for the system password. Supply it, and you're done. (This might not work for some Ubuntu releases, though.)Try
SUDO_EDITOR=kate sudo -e /path/to/the/file
. This will make sudo copy the file to a temporary directory, your editor is called as your unprivileged user, then when the editor returns (i.e. when it is closed), it will be copied to whatever privileged location.It also works with any other editor.
sudo -e
can also be spelledsudoedit
.You can try the following code and put it into a bash script. The motivation was
gksudo
with Wayland on Debian Buster. I'm right now not at yet Ubuntu 20.04 so I didn't tested it.