9

I'm using Kubuntu 18.04 and I want to run the kate editor with root privileges sudo kate produces the message running kate as root is not possible. I think that's utterly silly. How can I bypass it?

Answer: just edit the file, even if it's a system file, using plain oldkate. You don't need root privileges to edit it; you only need root privileges to save it. When you save a system file, you'll be asked for the root password. Supply it and the save takes place. Easy!!

Paul A.
  • 2,141
  • 5
    You can't without modifying the program and recompiling it afaik. You don't *need* to run kate as root anyway. As long as you have read privileges on the text file you can open it and if you make any changes when you try to save it will bring up a dialog box that will ask you for your password and will save the file successfully and "root" privileges will stay for the normal timeout you have on your system. (I think default is 5 minutes) – TrailRider Oct 09 '19 at 22:16
  • The GUI is owned by the user, and a secure environment shouldn't allow another user (root) to have access to a user's GUI. Your silly is security best practices, and whilst X may allow it (back from the early 80s where windows were from other machines due to slower cpus then in use), other more security-conscious enviornments (Wayland etc) will not. – guiverc Oct 09 '19 at 22:34
  • 1
    This explains why they disabled the ability to run kate as root. https://cgit.kde.org/kate.git/commit/?id=9adcebd3c2e476c8a32e9b455cc99f46b0e12a7e – mchid Oct 10 '19 at 00:29
  • 2
    There are many non-nanny editors that are every bit as good and even better than Kate. – Stephen Boston Oct 10 '19 at 00:37
  • 5
    Because of Bill Gates "We'll tell you what you can or can't do" mentality (I am beginning to think Linux is being taken over by ex MS programmers) I have just switched from Kate to GEDIT - too bad, I preferred Kate. I am re-thinking the whole KDE paradigm. I am a ex-sys admin living at home alone and they are trying to tell me how to use my computer - I don't think so! – jwzumwalt Dec 31 '19 at 20:40
  • 1
    Post your edit containing the "answer" as an actual answer. – Greenonline Nov 29 '21 at 22:18
  • Additional problem: What if you want Kate to act as a drop-in replacement for abominations like vim/emacs (I’m an old vim/emacs user, and I’ve been cured, thanks) in $EDITOR, You need to launch Kate from root, but not be root, but use the current user’s GUI instead, and if it’s not availabe, use e.g. tilde. –  Dec 15 '22 at 14:51

2 Answers2

11

I think I may have a newer version of kate installed. I'm running 18.04 and I get the following message:

Executing Kate as root is not possible. To edit files as root use:
SUDO_EDITOR=kate sudoedit <file>

so it seems you can edit files as root by using the following command:

SUDO_EDITOR=kate sudoedit <file>

However, you won't be able to edit files as root in any directory that is not owned by root. Because of this, you must also specify a filename when you run kate using sudoedit.


You can easily set an alias for sudokate by adding the following line to your ~/.bashrc file:

alias sudokate='SUDO_EDITOR=kate sudoedit'

Then, run the following command to source your ~/.bashrc file:

source ~/.bashrc

Also, don't forget to source your ~/.bashrc file in all other open terminals to apply the changes.

Now, you can run the sudokate command to edit files in directories owned by root.


SOURCE

mchid
  • 43,546
  • 8
  • 97
  • 150
10

You can edit system files with Kate 19.04.3 (available in Kubuntu 19.10) or in Kubuntu 19.04 (with kubuntu-backports ppa) installed.

Simply open the file you wish to edit in Kate, edit it, and click Ctrl+S. A PolicyKit window will appear prompting you for your password. Provide it and click Okay.

editing system files in Kate

DK Bose
  • 42,548
  • 23
  • 127
  • 221
  • 1
    This is a nice solution to the problem, and is adaptable (I think) to most environments. It works by avoiding the false paths of trying to run kate somehow with root privileges. The essential idea is marvelously simple: just edit your system file with vanilla kate, try to save it, and supply the root password when you're asked for it. – Paul A. Aug 05 '20 at 23:50
  • So what if you're actually logged in as root? – Joshua Aug 12 '20 at 03:30
  • @Joshua You shouldn't be. Follow good security practices and you won't run into this issue. – gronostaj Aug 12 '20 at 10:50
  • @gronostaj: Logging in as root on the console is a lot more secure than elevating a process in an X session. Even polkit can be hijacked. – Joshua Aug 12 '20 at 14:39
  • @Joshua Sorry, I don't follow. Why is logging in as root (to perform some task) more secure than running selective processes as root? And what does X have to do with it? What do you mean by "even polkit can be hijacked"? – gronostaj Aug 12 '20 at 17:03
  • @gronostaj: A libc trojan can hijack exec() to do something else, like give you a fake login prompt and pass the real password to its own invocation of sudo. But a libc trojan can't hijack through Ctrl-Alt-Fn followed by root login and startx. – Joshua Aug 12 '20 at 21:05
  • @Joshua Can a libc trojan be installed without root in the first place? – gronostaj Aug 13 '20 at 06:11
  • @gronostaj: Yes. All it needs is to write to .Xsession and set LD_LIBRARY_PATH or LD_PRELOAD. – Joshua Aug 13 '20 at 13:49
  • What can you do when the policykit does not open this prompt? How do you enable it? – Akito Feb 25 '21 at 22:45