Unable to edit /etc/postfix/main.cf with kate using SUDO_EDITOR=kate sudoedit /etc/postfix/main.cf

I am trying to use kate to edit /etc/postfix/main.cf. When I run the below command, it opens kate, but it opens to a temp file that does not have the content of /etc/postfix/main.cf as expected.

SUDO_EDITOR=kate sudoedit /etc/postfix/main.cf

If I open the file in kate directly, from the GUI, I can open it but I can’t save it.

How can I use kate to edit these files?

1 Like

Its my understanding that you open files with Kate without using the sudo command. Then when you save it does it so as the root after it prompts for password.

try just:

kate /etc/postfix/main.c

1 Like

That is what I read too, but it never prompts for password. See the screenshot in my post. That is the error I get when trying to save.

1 Like

Your system’s PolKit rules may be set up incorrectly.

Or, if you’re using openSUSE, it would be because they patched out the feature.

What distro are you using?

1 Like

I am on openSUSE but I thought that this issue would have been patched since it was raised years ago?

Either way, I think I found a fix and wrote a helper function for myself:

# open a file in kate for editing
# if the current user has write access to the file, it'll open kate as the current user
# if the current user does not, it'll open the file in kate with sudoedit
function nedit()
    # file passed down from input

    # if the file does not exist
    if [[ ! -f "$fileOrPathToCheck" ]]
        # we need to check the folder
        fileOrPathToCheck=$(dirname "$fileOrPathToCheck")

    # if the file or folder can be written to by the current user
    if [[ -r "$fileOrPathToCheck" && -w "$fileOrPathToCheck" ]]
        # just open with kate
        kate "$fileToEdit"
        # else open with kate using sudoedit
        export VISUAL="kate -b"
        sudoedit "$fileToEdit"
        unset VISUAL

No unfortunately, OpenSUSE continues to patch it out while simultaneously patching back in the ability to run Dolphin as root, which I’ll admit doesn’t make a lot of sense to me.


Got it.

And I found the reason why: Reddit - Dive into anything

@imthenachoman, in general, you shouldn’t be running GUI programs as root, unless you really know what you’re doing (and even then, you should reconsider it and find another way). Your helper function is not a good idea.

That’s why there is polkit support in Kate, so that you can edit root-owned files while running Kate without root privileges. However, if that feature is patched out on your distro, you’re out of luck. In that case, when you need to edit files owned by root, it’s probably best stick to a terminal-based text editor, like Vim or Nano.


Yes, I agree. You generally you shouldn’t. But for home use, the risk is super low and the convenience of editing files in a GUI is worth it. It’s high ROI.

I know vi, and vim, and nano, and numerous others, but, sometimes, I just wanna GSD and GUI is the way to go.

I’m trying to find out if it’s possible to enable it in openSUSE somehow. If not, I’ll keep using my helper script for the rare occurrences I need to edit a file.

Why? What risk? How is it different if it is home use or not?

If you know Vi and Nano, why is it easier to invoke some script rather than a terminal + the command nano filename, for example.

Well, a few things:

  • Invoking a script is the same as calling vi or nano. So no change there.
  • In fact, my script takes care of checking if the current user has read/write access, cause if it doesn’t then it’ll use sudoedit.
  • And doing things in GUI is always going to be faster. I can scroll more quickly, I can copy/paste with CTRL+C/CTRL+V easier, finding is faster with CTRL+F and going through all the occurrences, etc. I used to managed 300k large *NIX environments and am know my way around the terminal, but, generally, GUI is just faster and easier.

In that case,as you seem sufficiently capable, why not find out what the polkit settings are for kate, and add the polkit config back in.

Then you can do it in a GUI the proper way.

Ha. If I’ve learned one thing, it’s not to reinvent the wheel. I was trying to see if anyone else had already solved it. But it doesn’t look like it. When I have time, I will investigate more. But for my immediate use, my helper script works for me.

Also, I thought support was patched out, not a PolKit setting.