How to run Dolphin as root?

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

  • Re-allow running Dolphin as the root user (but still not using sudo): https://phabricator.kde.org/D12795

  • Show a warning when running as the root user: https://phabricator.kde.org/D12732

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


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..


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 ;)

Tags:

Kde

Root

Dolphin