33

I currently use Dolphin 17.04.3 and whenever I run it as sudo, it gives the following error:

Executing Dolphin as root is not possible.

without explaining why or giving an alternative.

How can I run Dolphin as root for copying or deleting files?

7
  • 1
    are you using wayland? by default wayland does not allow GUI programs to run as root.
    – ravery
    Dec 29, 2017 at 17:42
  • doesn't work. the option to create or move files is simply greyed out in the context menu. Please check your version
    – Ankur S
    Dec 29, 2017 at 17:51
  • I'm using ubuntu 17.10 and x11 with kde installed
    – Ankur S
    Dec 29, 2017 at 17:56
  • Juan, I want to try your script, but I can't find a folder "kservices5" in .local/share. Any advice? I do find one with that name in usr/share, is that the one? Mar 11, 2019 at 12:57
  • @ravery - it seems that the service menu available now (see my answer has an option for wayland: if [ "$XDG_SESSION_TYPE" = "wayland" ]; then xhost +si:localuser:root && pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY KDE_SESSION_VERSION=5 KDE_FULL_SESSION=true dbus-launch dolphin %U && xhost -si:localuser:root ; else pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY KDE_SESSION_VERSION=5 KDE_FULL_SESSION=true dolphin %U; fi;
    – cipricus
    Jun 23, 2022 at 15:33

11 Answers 11

22

Short:

Dolphin 17.04

The Dolphin 17.04 or later has a check:

if uid == 0 then show the "Executing Dolphin as root is not possible." and exit.

A workaround

You could edit the sources and disable the check. Then the Dolphin will work as before.

Dolphin 18.08

Few review request

Dolphin 18.08.0 is using these changes and the Dolphin can be launched with the pkexec command as the administrative super user.

pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY KDE_SESSION_VERSION=5 KDE_FULL_SESSION=true dolphin

More: KDE Foruns - How to run Dolphin 18.08 as root with Kubuntu or KDE neon? - https://forum.kde.org/viewtopic.php?f=224&t=153655

enter image description here

Background:

Earlier - KDE Forums - How to run Dolphin as root?: https://forum.kde.org/viewtopic.php?f=224&t=141836

For the security reasons: Disallow executing Dolphin as root on Linux - https://cgit.kde.org/dolphin.git/commit/?id=0bdd8e0b0516555c6233fdc7901e9b417cf89

Disallow executing Dolphin as root on Linux Basically a copy of commit kate/9adcebd3c2e476c8a32e9b455cc99f46b0e12a7e which was written by Martin Grässlin

Disallow executing kate and kwrite as root on Linux: https://phabricator.kde.org/R40:9adcebd3c2e476c8a32e9b455cc99f46b0e12a7e

More tips

KDE Reddit - Dolphin root on KDE App 17.04 : https://www.reddit.com/r/kde/comments/6785b1/dolphin_root_on_kde_app_1704/

Bypass "Executing Dolphin as root is not possible" and Regain KDE Dolphin Root Privileges: https://www.reddit.com/r/kde/comments/6xs3mp/bypass_executing_dolphin_as_root_is_not_possible/

Future

Polkit support in KIO: https://phabricator.kde.org/T6561

When it is ready the Dolphin will show the password query if needed. Now, with the patched Dolphin&KIO:

enter image description here

5
  • 1
    Could you elaborate a little bit more on the "For the security reasons"? Feb 26, 2018 at 21:21
  • Did you read the phabricator.kde.org/… . Same / more : Martin Grässlin - Editing files as root: blog.martin-graesslin.com/blog/2017/02/editing-files-as-root
    – user26687
    Mar 5, 2018 at 9:47
  • 1
    so, the simple answer is "you cannot run Dolphin as root, unless you install a patched version"?
    – user47206
    Jun 22, 2018 at 9:56
  • @user47206: Why not patch it yourselfs ? ;) See my answer below !
    – WitchCraft
    Oct 11, 2019 at 4:15
  • I want to recommend a slight change in your command to run Dolphin as root. I just needed to add dbus-launch in the line to execute the command successfully. So the command becomes sudo pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY KDE_SESSION_VERSION=5 KDE_FULL_SESSION=true dbus-launch dolphin
    – Mumuzab
    Sep 10, 2021 at 5:49
14

Not an answer, just a workaround for the purpose mentioned by the OP (copying or deleting files).

The idea is to

  1. install another file manger that doesn't have that limitation and that doesn't bring a lot of dependencies

  2. create an "Open as root" context menu in Dolphin for this other file manager.

The main file managers of other desktops can be used (Nautilus, Nemo, Caja, Thunar) but they do bring some dependencies. Even PCManFM and PCManFM-Qt do that. If you need one of those for some other purpose adding that one could be a good solution.

I have found that Krusader (which I think in the past used to be installed by default in some KDE systems) can be easily installed, brings no dependencies in Kubuntu 18.04, and can be used as root.

sudo apt install krusader

Under its Tools it has the "Root" option.

enter image description here

which asks for password in a gui.

To add a context menu in dolphin, create the folder ~/.local/share/kservices5/ServiceMenus and then do

kate ~/.local/share/kservices5/ServiceMenus/filemanager_root.desktop

and add

[Desktop Action root]
Exec=/usr/lib/kde4/libexec/kdesu krusader
Icon=dolphin
Name=Open in Krusader file manger as administrator

[Desktop Entry]
Actions=root
Icon=krusader_root
MimeType=inode/directory
ServiceTypes=KonqPopupMenu/Plugin
Type=Service
X-KDE-Priority=TopLevel
X-KDE-StartupNotify=false

For some reason kdesu krusader doesn't work, and I have used the solution from here.. What also works is konsole -e sudo krusader, but that shows the terminal instead of a gui for the password prompt.

Then, you'll see in Dolphin:

enter image description here

bringing a dialog

enter image description here

which is one that works..

0
6

I have made my own version based on the replies above. So, to add a context menu to open Dolphin as root follow these steps:

  • Create a file called for example DolphinAsRoot.desktop on the directory ~/.local/share/kservices5/ServiceMenus/
  • With a text editor put the following content on it:
[Desktop Entry]
Actions=root
Icon=system-file-manager-root
MimeType=inode/directory
ServiceTypes=KonqPopupMenu/Plugin
Type=Service
X-KDE-Priority=TopLevel
X-KDE-StartupNotify=false

[Desktop Action root]
Exec=/usr/bin/pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY KDE_SESSION_VERSION=5 KDE_FULL_SESSION=true dolphin
Icon=system-file-manager-root
Name=Open as administrator
  • If it still not appears on the context menu in Dolphin go to "Settings -> Configure Dolphin...-> Services" and activate the option you recently added. It should be there. If not, close Dolphin or even log out and in on your session.

That's all, I hope it helps you all like it helped me ;)

5

In current version (21.08.0) you can trick Dolphin by erasing the $SUDO_USER shell variable when running it with sudo. This simple command will work:

sudo SUDO_USER= dolphin
3

It's trivial !

Just look at the source code of kate and kwrite:

diff --git a/kate/main.cpp b/kwrite/main.cpp

In the first lines of code directly at the start of the "main" function, you’ll find:

/**
 * Check whether we are running as root
 **/
if (getuid() == 0) // uid = user id = 0 ==> means if you are user 0 (aka root)
{
    std::cout << "Executing Kate as root is not possible. To edit files as root use:" << std::endl;
    std::cout << "SUDO_EDITOR=kate sudoedit <file>" << std::endl;
    return 0;
}

Dolphin is no different, except this happens in libkdeinit5_dolphin.so.

So running as root is trivial, all we need to do is skip the if uid=0 check.

The way we do this, is by perma-patching kate, kwrite and dolphin.
So, the first thing we do, is dumping the binary content to a text-file:

objdump -Crd /usr/bin/kate >> ~/kate.txt
objdump -Crd /usr/bin/kwrite >> ~/kwrite.txt

Now you can look at the file with gedit ~/kate.txt, and if you search for getuid, you'll find something like:

   2a985:   31 c0                   xor    %eax,%eax
   2a987:   89 bc 24 dc 00 00 00    mov    %edi,0xdc(%rsp)
   2a98e:   e8 ed ce ff ff          callq  27880 <getuid@plt>
   2a993:   85 c0                   test   %eax,%eax
   2a995:   0f 84 e9 1e 00 00       je     2c884 <__cxa_finalize@plt+0x1f5c>

Now, on the left side, you find the memory address, after the colon (:) you'll see the binary instruction code (hex) and to the right of that, you see the disassembly of that code (aka what it means).

Now, you see, there it calls getuid, tests if that is zero and jumps into the if-statement, that is to say if the return value is equal to zero (je: jump if equal).

Now we don't want to jump into the if, so we just remove that crap there. But just removing that crap would change addresses by 6 bytes, trashing any relative jumps in the program in the process, and as a consequence, the program. So instead you just replace the entire length of the jump statement with NOP (short for No Operation) instructions, aka 0x90 in instruction code/hex.

So you need to replace every jump byte there with 0x90 so where you previously had

0f 84 e9 1e 00 00

you will have

90 90 90 90 90 90

This can be done simply with a hex-editor.
So we install one:

sudo apt-get install wxhexeditor

Now in the hex editor, you search for 0f 84 e9 1e 00 00, and replace that with 90 90 90 90 90 90. If there's only one occurency of 0f 84 e9 1e 00 00, and there is, then this is trivially simple. Just change the bytes in hex to 90 90 90 90 90 90 and save. Finished. Kate or kwrite will now open, whether you are root or not.

if you do the same with dolphin, you'll realize objdump -Crd /usr/bin/dolphin produces a very short disassembly.

if you run ldd /usr/bin/dolphin, you'll see dolphin loads the shared library libkdeinit5_dolphin.so

linux-vdso.so.1 (0x00007ffc2fdf0000) libkdeinit5_dolphin.so => /usr/lib/x86_64-linux-gnu/libkdeinit5_dolphin.so (0x00007fb54e76c000)

So you do the objdump on libkdeinit5_dolphin.so:

objdump -Crd /usr/lib/x86_64-linux-gnu/libkdeinit5_dolphin.so >> ~/libkdeinit5_dolphin.txt

Now open the objdump: gedit ~/libkdeinit5_dolphin.txt

Search for getuid, and you'll see that one of the search results is:

   41f95:   31 c0                   xor    %eax,%eax
   41f97:   89 7c 24 5c             mov    %edi,0x5c(%rsp)
   41f9b:   e8 50 b6 ff ff          callq  3d5f0 <getuid@plt>
   41fa0:   85 c0                   test   %eax,%eax
   41fa2:   0f 84 58 1a 00 00       je     43a00 <kdemain@@Base+0x1a90>
   41fa8:   48 8d 84 24 a0 00 00    lea    0xa0(%rsp),%rax

This is great, you see, more crap just like in kate and kwrite.
Now open /usr/lib/x86_64-linux-gnu/libkdeinit5_dolphin.so in your hex-editor, search for 0f 84 58 1a 00 00 and replace it with 90 90 90 90 90 90.
Hit save, and done.

Dolphin now runs as root.

Note: Good idea to make a backup copy of the files you modify, just in case you f*** up.

Also, you could just download the source of kate, kwrite, and dolphin, remove that crap from the source code, compile and install. But since the stupid cmake system is missing some crappy crap template for some stupid crap such as icons, probably because the repo-supplied cmake is too old, this doesn't work. Too bad, would have been too simple if it just worked, wouldn't it.

But just patching the executables as I described is faster, so who cares anyway.

You see, it's not straightforward, but it's trivial.

PS:
Now, any time kate, kwrite or dolphin are updated via apt, your changes will be overwritten. You'll need to re-apply them. I'll leave automatizing the patch-process in your more than capable hands, and your programming language of joice ;)

Can this be done in pure bash ?

Also, if you want to patch vlc for the same crap, you can do it with sed:

sed -i 's/geteuid/getppid/' /usr/bin/vlc

Just put that sed-statement into a script, so you can re-apply, if you ever need to if you are offline and have no internet access.

Happy hacking - with kate, kwrite and dolphin - as root - while watching/listening to something on vlc.

PS2:
The crappy root checks went the way of the Dodo in KDE v19.04.
Who said nevolution was a bad thing.
To progress - Cheers !

2
  • 3
    Yes. Very trivial!
    – Qumber
    Jun 24, 2021 at 15:59
  • @Qumber: Replace some "text" with some other "text". I call that trivial. If it were a text file in notepad, you'd CTRL+H > text to search > text to replace > CTRL+A > CTRL+S > ALT+F4, and you'd be finished. Wouldn't even need a mouse.
    – WitchCraft
    Jul 5, 2021 at 9:01
2

Kubuntu 22.04, Dolphin 21.12.3 accepts again being opened as root. There is a context menu service for that

enter image description here

Settings - Configure Dolphin - Context Menu - Download new services, search for "open dolphin as root"...

Or you can find it here. Put it into ~/.local/share/kservices5/ServiceMenus/.

The command in question is rather interesting:

if [ "$XDG_SESSION_TYPE" = "wayland" ]; then xhost +si:localuser:root && pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY KDE_SESSION_VERSION=5 KDE_FULL_SESSION=true dbus-launch dolphin %U && xhost -si:localuser:root ; else pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY KDE_SESSION_VERSION=5 KDE_FULL_SESSION=true dolphin %U; fi;

Note that simply editing a file doesn't require that, as Kate can open any file and ask for root password when saving changes.

1

You never need to run Dolphin as root! If you want to write to a protected file, just go ahead and do it. Dolphin will ask you for permission. Then confirm the operation. I do this all the time.

Actually, I'll admit this isn't a perfect solution -- it doesn't cover the rare case where the file you want to edit is hidden, i.e., the directory it appears in doesn't have execute permission. I don't know what to do in that situation.

0

Alls I did was add the Terminal to the toolbar (although keyboard shortcut bound to F4) and used the command line to perform operations as sudo as required.

Like so

Yeah it might not be as convenient but it forces you to start learning the command line whilst giving you visual representation of how the command actually works.

This is on Arch but the functionality should be the same on Ubuntu. Hope that helped.

0

here it is a workaround for Dolphin 17.x:

export XDG_CURRENT_DESKTOP=KDE; LD_PRELOAD=/home/roger/Downloads/dolphin/usr/lib64/libkdeinit5_dolphin.so /usr/bin/dolphin

get libkdeinit5_dolphin.so from here

Tested by me, it works fine in Ubuntu bionic.

source

0

Not a solution, but a suggestion.... Altering Dolphin and files is rather risky. Double Commander is an excellent alternative, and is found in the respository. It will install without root proviledges. To gain root, simply enter 'sudo doublecmd' in the terminal. It has many advantages when working with large and millions of files.

0

Follow CallofCode's Answer In my case, kde neon was not allowing install of any icons or themes and the only way was to cli copy files into folders which is unnecessary and tedious for basic things in 2022

Create a file called DolphinAsRoot.desktop in the directory ~/.local/share/kservices5/ServiceMenus/ With a text editor put the following content on it:

[Desktop Entry] Actions=root Icon=system-file-manager-root MimeType=inode/directory ServiceTypes=KonqPopupMenu/Plugin Type=Service X-KDE-Priority=TopLevel X-KDE-StartupNotify=false

[Desktop Action root] Exec=/usr/bin/pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY KDE_SESSION_VERSION=5 KDE_FULL_SESSION=true dolphin Icon=system-file-manager-root Name=Open as administrator

restart dolphin and it should be there with a right click

1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .