pcmanfm "edit as root"

17 Antworten [Letzter Beitrag]
linuc
Offline
Beigetreten: 10/17/2021

Hi

I am working with Trisquel Mini.

I miss the "Edit as root" function in pcmanfm and would like to create it. I found some information on other forums, but none worked.

Example:

https://forums.bunsenlabs.org/viewtopic.php?id=7248

Does anyone have a solution so that I get an option "Edit as root" in the context menu?

Thanks very much!

gaseousness
Offline
Beigetreten: 08/25/2020

Perhaps the line

Exec=gksudo mousepad %f

can be replaced with

Exec=pkexec mousepad %f

linuc
Offline
Beigetreten: 10/17/2021

No, unfortunately it has no effect. In the context menu I have the option "Edit as root", but when I click it nothing happens. The file is called root.desktop and is in /home/trisquel/.local/share/file-manager/actions.

Permissions is:
View content: anyone
Change content: Only owner
Execute: anyone

Desktop entry:
Command: "empty field"
The rest is also all empty.

File content is:
[Desktop Entry]
Type = Action
Name = Edit as root
Icon = dialog-password
Profiles = profile-zero;

[X-Action-Profile profile-zero]
MimeTypes = text / *; application / *;
Exec = gksudo pcmanfm % f
Name = default profile

or: Exec = pkexec pcmanfm % f

jahoti
Offline
Beigetreten: 07/31/2021

Shouldn't "gksudo pcmanfm % f" be "gksudo % f" (where is "mousepad" or whatever text editor you have installed)?

linuc
Offline
Beigetreten: 10/17/2021

@jahoti

Yes you are right, there must be leafpad :-)

But unfortunately it doesn't work even then. Not even the password is requested. Nothing happens.

vita_cell
Offline
Beigetreten: 07/19/2015

I will pass my custom actions from Thunar (/home/$USER/.config/Thunar/uca.xml), and hope it helps you a bit:

EDIT: well, somehow the xml code is absolutelly broken here, so I add a file in txt.

<?xml encoding="UTF-8" version="1.0"?>

/usr/share/icons/Chicago95-tux/apps/16/Terminal.png
Abrir un terminal aquí
1615546850394789-2
exo-open --working-directory %f --launch TerminalEmulator
Ejemplo de una acción personalizada
*

/usr/share/icons/Chicago95-tux/mimes/16/application-install.png
Extraer aqui
1611391778326262-14
tar xjf %n

*.tar.bz2;*.tbz2

/usr/share/icons/Chicago95-tux/mimes/16/application-install.png
Extraer aqui
1611391771541354-13
unzip %f

*.zip

/usr/share/icons/Chicago95-tux/mimes/16/application-7zip.png
Comprimir
1571433401279157-4
tar czvf %n.tar.gz %n

*

/usr/share/icons/Chicago95-tux/apps/16/Terminal.png
Abrir terminal aqui como root
1611391655989001-9
sudo exo-open --working-directory %f --launch TerminalEmulator

*

/usr/share/icons/Chicago95-tux/emblems/16/emblem-symbolic-link.png
Crear enlace simbolico
1571434372897409-10
ln -s %f “%n (symlink)”

*

/usr/share/icons/Chicago95-tux/apps/16/accessories-text-editor.png
Editar como superusuario
1571435252017328-13
sudo leafpad %f

*

/usr/share/icons/Chicago95-tux/mimes/16/application-install.png
Extraer aqui
1611391761151341-12
tar -xvzf %n

*.tgz

/usr/share/icons/Chicago95-tux/places/16/folder.png
Abrir carpeta como root
1571440386210146-18
sudo thunar %f

*

/usr/share/icons/Chicago95-tux/devices/16/media-optical-dvd-rw.png
Instalar paquete
1612429789433345-1
xfce4-terminal --command='sh -c "if sudo /sbin/installpkg %n | grep installed; then sleep 5&& exit; else echo Package install FAILED; fi"'

*.tgz;*.txz

/usr/share/icons/Chicago95-tux/mimes/16/binary.png
Compilar programa
1612429397748049-1
xfce4-terminal --command="sudo ./%n" --hold

*.SlackBuild

/usr/share/icons/Chicago95-tux/mimes/16/application-x-rpm.png
Extraer aqui
1571491503778088-1
tar -xJf %n

*.tar.xz

/usr/share/icons/Chicago95-tux/mimes/16/application-x-rpm.png
Extraer aqui
1571491622097361-3
tar xvzf %n

*.tar.gz

/usr/share/icons/Chicago95-tux/emblems/16/emblem-generic.png
Suma de verificación
1596875051551827-4
gtkhash %n
Obtener codigo criptográfico
*

/usr/share/icons/Chicago95-tux/apps/16/application-default-icon.png
Ejecutar en terminal
1597304997025412-4
xfce4-terminal -x ./%n
Ejecutar un script en una terminal
*.sh

/usr/share/icons/Chicago95-tux/mimes/16/application-x-rpm.png
Extraer aqui
1611367178025996-4
tar --lzip -xvf %n

*.tar.lz

/usr/share/icons/Chicago95-tux/apps/16/xmms.png
Reproducir con XMMS
1612221998215277-1
xmms %F
Reproduzca archivos de audio
*

/usr/share/icons/Chicago95-tux/actions/16/document-edit-symbolic.png
De mayusculas a minusculas
1612223392773622-4
for file in %N; do mv "$file" "$(echo "$file" | tr '[:upper:]' '[:lower:]')"; done
Sustituye los nombres de archivos que contienen mayusculas y las transforma a minusculas
*

/usr/share/icons/Chicago95-tux/apps/16/inkscape.png
Reducir el color a 8 bits
1612225224765061-5
for file in %F; do pngnq -s1 "$file" -e -8bits.png; done
Reduce el color de un archivo de imagen a 8 bits
*.png

p7zip
Comprimir con p7zip
1615607341742094-3
p7zipForFilemanager ad -t7z %F

*

AnhangGröße
uca.txt 6.55 KB
linuc
Offline
Beigetreten: 10/17/2021

Gracias :-)

vita_cell
Offline
Beigetreten: 07/19/2015

Why "% f" and not "%f"? Is that correct? At least in xfce it's always "%something", without space. From where you get that space?

linuc
Offline
Beigetreten: 10/17/2021

I think it is coming from copy/paste here in the forum, as there is no "code-function" to post. Should be %f.

linuc
Offline
Beigetreten: 10/17/2021

Well, I did some more practice, but it didn't work. Then I googled why pcmanfm doesn't have the "edit as root" function. Apparently there are people who have no greater problem than "protecting" other people from taking a "dangerous" action. Which then leads to other people opening pcmanfm using the terminal as root, which is then "less dangerous"? At least if you consider it dangerous if you accidentally delete a file and then have to reinstall your Linux distribution. Yes, dangers lurk everywhere :-)

I have now installed Nautilus, there the risk seems to be less, because it has the function "edit as root". Bad luck for the creators of pcmanfm that they are not alone in the world and that there are other people who are less fearful.

But if someone knows the solution with pcmanfm ... I haven't uninstalled it yet :-)

gaseousness
Offline
Beigetreten: 08/25/2020

true

gaseousness
Offline
Beigetreten: 08/25/2020

Something like this may work, create a .desktop file under ~/.local/share/applications/

~/.local/share/applications/editasroot.desktop

Add the following to the file ~/.local/share/applications/editasroot.desktop

[Desktop Entry]
Name=Edit As Root
Comment=Edit As Root
X-GNOME-FullName=Edit As Root
Exec=sudo mousepad %u
Terminal=true
X-MultipleArgs=false
Type=Application
Icon=mousepad
Categories=System
MimeType=text/plain

Right click on a text file, choose open with then select system tools, and pick edit as root, from now on it should be an option when you right click on text files. There's a command sudoedit which opens a terminal text editor more safely as non-root but then saves it as root, not aware of a graphical text editor way to do this, but this should be a workaround one may want to consider if it suits his or her needs? Replace mousepad, with the text editor of choice. Also, one could try changing the line Terminal=true to Terminal=false and Exec=sudo mousepad %u to Exec=pkexec mousepad %u, but pkexec can be weird, I guess, at least from my experiences. Also, with pcmanfm one can just use the F4 key to open a terminal in the curent directory pcmanfm is in then sudo mousepad file, or sudoedit file, or something like that?

c1ca1a578607005f4d0adc9ae3923da5.jpg
linuc
Offline
Beigetreten: 10/17/2021

Yes! It is working :-)

Thanks very much!

I could not create the file directly in the folder ~ / .local / share / applications / and had to create it first via leafpad and save it in a personal folder, then move it. But maybe it was a nautilus problem.

My file:

[Desktop Entry]
Name=Edit As Root
Comment=Edit As Root
X-GNOME-FullName=Edit As Root
Exec=sudo leafpad %u
Terminal=true
X-MultipleArgs=false
Type=Application
Icon=leafpad
Categories=System
MimeType=text/plain

jbar
Offline
Beigetreten: 01/22/2011

Using sudo with graphical applications is potentially dangerous.
https://help.ubuntu.com/community/RootSudo#Graphical_sudo

Starting GUI applications with admin privileges is not always easy.
https://beamtic.com/sudo-and-guis

gaseousness
Offline
Beigetreten: 08/25/2020

"Thanks very much!"

You're welcome.

Looks like it'd be better to change the line

Exec=sudo leafpad %u

to

Exec=sudo -H leafpad %u

Good point out jbar.

"With sudo -H almost any graphical app can be launched under root within any 'buntu flavour. This includes each flavour's default graphical editor and file manager.

An appreciable danger with sudo -H is that the -H flag is easy to forget. And all it takes is one omission for the damage to be done. "
https://help.ubuntu.com/community/RootSudo#Graphical_sudo

damidu
Offline
Beigetreten: 03/30/2021

Yeah that's true you shouldn't work as root for anythings.

"root" has unlimited rights.

You could execute malware code with unlimited rights on your system (from a pdf file, a bad package, an application bug, ...) or you could delete a file in the wrong directory.

But you know that :-) It's funny to do one time.

linuc
Offline
Beigetreten: 10/17/2021

I can always reinstall Nautilus if it gets too "dangerous" ;-)

gaseousness
Offline
Beigetreten: 08/25/2020

Changing the line

Exec=sudo -H leafpad %u

to

Exec=sh -c "export EDITOR=leafpad ; sudoedit "%f""

Appears to run the graphical text editor not as root, and only let's me edit files root's supposed to like text files under /etc/