User avatar
paulwratt
Posts: 83
Joined: Fri Jun 12, 2015 12:15 am

PCManFM right click menu and Open As Root

Mon May 02, 2016 11:27 am

Took me a while to get these working so I thought I would post them and some info related to them
EDIT: my personal right click list contains:
file.node: Edit as Root (Leafpad via x-editor)
file.node: Play Sound (sdlPlay.cpp, SDL1.2 works without X too)
file.node: Show Picture (sdlSlide.cpp, SDL1.2 works without X too)
file.node: View Font (sfontview.c, SDL1.2 works without X too)
dir.node: Open Terminal (cd-xterm.sh)
dir.node: Open Folder as Root (PCManFM new window)
dir.node: Open as Root (cd-xterm.sh)
[UPDATE] updates cd-term.sh and zip

The attachment contains complete files as saved with Nautilus-Actions Configuration Tool (nautilus-actions-config-tool) which is part of the nautilus-actions package (no need for all things Nautalus).

These right click menu items unfortunately dont work with SpaceFM (maybe a different actions folder?)

first you need to create the right directory structure: ~/.local/share/file-manager/actions
in your home (/home/pi) directory:

Code: Select all

mkdir -p .local/share/file-manager/actions
I use vim (not nano or emacs) (.local is a hidden folder) :

Code: Select all

vim.tiny .local/share/file-manager/actions/open\ folder\ as\ root.desktop
(you type backslash + space to get a space in a filename, tab completion can teach you alot)
press insert key (will toggle insert/replace)
paste the following into vim (or your editor) (console is shift+ins to paste selected)

Code: Select all

[Desktop Entry]
Type=Action
Tooltip=Open Folder As Root
Name=Open Folder As Root
Icon=gtk-dialog-authentication
Profiles=on_folder;

[X-Action-Profile on_folder]
Exec=gksudo pcmanfm %f
MimeTypes=inode/directory;
press escape key (ESC), then type (it will come up down the bottom):

Code: Select all

:wq
and hit enter. that stands for command (:), write (:w), quit (:q)

if you are at the console command line again the file "open folder as root.desktop" has been saved (type ls to check), if not then something went wrong, dont worry start again..

here are two other useful right click items:
open as root.desktop

Code: Select all

[Desktop Entry]
Type=Action
Name=Open as Root
Tooltip=Open the folder as root
Icon=terminal
Profiles=on_folder;

[X-Action-Profile on_folder]
Name=Open as Root
MimeTypes=inode/directory;
Exec=/home/pi/bin/cd-xterm.sh %f
cd-xterm.sh

Code: Select all

#!/bin/sh
cd "$1"
if [ "$2" = "" ]; then
 gksudo x-terminal-emulator &
else
 x-terminal-emulator &
fi
exit 0
(& ampersand at the end makes command run in the background, not waiting for it to finish)
usage:

Code: Select all

cd-xterm path  (open x-terminal-emulator at path as root)
cd-xterm path is_user (open at path as current user)
(last option allows you to right click without selecting folder to open regular terminal session - PCManFM need some work ...)

edit as root.desktop

Code: Select all

[Desktop Entry]
Type=Action
Tooltip=Edit file as root user
Name=Edit as Root
Icon=txt
Profiles=on_file;

[X-Action-Profile on_file]
Exec=gksudo x-editor %f
MimeTypes=!inode/directory;*;
for that last one you will also need the following:

Code: Select all

sudo ln -s /usr/bin/leafpad /etc/alternatives/x-editor
sudo ln -s /etc/alternatives/x-editor /usr/bin/x-editor
those are softlinks (ln -s target linkname). I used Leafpad as the default X Windows Editor, you can use something else. editor is the default console editor.

BTW all user make right click menu items in PCManFM show up at the bottom of the menu.


Cheers
Paul
Attachments
pcmanfm as root right click menus-0.3.zip
(2.34 KiB) Downloaded 188 times
Last edited by paulwratt on Wed Feb 15, 2017 2:17 am, edited 6 times in total.

User avatar
Rive
Posts: 586
Joined: Sat Mar 26, 2016 5:21 pm
Location: USA

Re: PCManFM right click menu and Open As Root

Mon May 02, 2016 12:42 pm

Perhaps I am not understanding what you are trying to accomplish, but for root access in file manager all you need to use is this command:

Code: Select all

gksu pcmanfm
on the directory itself via FM "Tools" tab (Run a command in current folder). Done. Root Access (until folder is closed).
DNPNWO

User avatar
paulwratt
Posts: 83
Joined: Fri Jun 12, 2015 12:15 am

Re: PCManFM right click menu and Open As Root

Mon May 02, 2016 1:10 pm

that requires typing. this is a point and click universe with insta-everything service. They could have at least made it an option (to turn it on), ... <insert rant here>

the bottom line, if you are searching for the above info, now you have a working answer.
if you need the above info, its because you are making frequent system/root level changes.

(I was gonna say thanks for the other info but you deleted the rest of you post :) )

[edit] this post will also teach you: how to put those missing features back in; where to place your own non-root access right click commands; how to getany terminal emulator to work off a given directory; where to place your own commands that are not required by the system; how to use vim to edit a file. amonst other things..

Paul

User avatar
Rive
Posts: 586
Joined: Sat Mar 26, 2016 5:21 pm
Location: USA

Re: PCManFM right click menu and Open As Root

Mon May 02, 2016 1:20 pm

paulwratt wrote:that requires typing. this is a point and click universe with insta-everything service. They could have at least made it an option (to turn it on), ... <insert rant here>

the bottom line, if you are searching for the above info, now you have a working answer.
if you need the above info, its because you are making frequent system/root level changes.

(I was gonna say thanks for the other info but you deleted the rest of you post :)

Paul

You mean for root access.I can repost it. sudo su startx might get someone in trouble though (create a backup image for recovery before mucking around with root permissions and .Xauthority). It also may be a bad idea to setup full root access via right click on a non-root user account. If you want full root access, then login as root, enable and set root password.

Code: Select all

sudo su
startx
If needed, here is how to recover non-root access via login
When you get to your log in screen press CTRL + ALT + F1 to get to a terminal, then type in your user name and pw to login. Then type sudo chown user:user ~/.Xauthority where user:user is your username followed by a colon, then your username again. You could also just do sudo rm ~/.Xauthority and remove the file, as it will get generated again the next time you login.

Enable root, set password:

Code: Select all

sudo passwd root
Set password, confirm password, logout, then login with root and password.


Disable root access:

Code: Select all

sudo passwd -l root
DNPNWO

User avatar
jojopi
Posts: 3085
Joined: Tue Oct 11, 2011 8:38 pm

Re: PCManFM right click menu and Open As Root

Mon May 02, 2016 1:54 pm

You could also just do sudo rm ~/.Xauthority and remove the file, as it will get generated again the next time you login.
You do not need sudo to delete another user's file, if it is in your directory.

Running the whole GUI under sudo is still a really bad idea, though. There is no guarantee that the resulting ownership issues will be limited to .Xauthority.

User avatar
paulwratt
Posts: 83
Joined: Fri Jun 12, 2015 12:15 am

Re: PCManFM right click menu and Open As Root

Mon May 02, 2016 2:23 pm

When Raspian was first released you could login as root, and it is something I have done on all my Linux setups

That allows you to "see" when you are using apps as root, as mostly either regular theme gets changed, of you can change the one as root user. So on screen you will see 2 different window decorations.

Anyway I (most days) edit /etc/hosts while I am web browsing, or doing something that I need root access. there are now things that even sudo cant do, sorry cant specify any off the top of my head, but I have found a few in the last few weeks.

BTW I seem to remember "dont use regedit" on Windows. If it were not for regedit I would have had to run anti-virus and firewall, rather manage that stuff by hand, you get a quicker more stable machine and you learn A LOT (yes you can break a lot).

Paul

@jojopi
unless its a root:root file, to remove use:

Code: Select all

sudo rm filename
or to gain control:

Code: Select all

sudo chmod +r filename
sudo chown pi:pi filename

User avatar
paulwratt
Posts: 83
Joined: Fri Jun 12, 2015 12:15 am

Re: PCManFM right click menu and Open As Root

Thu Feb 09, 2017 9:43 am

bumped

in cd-xterm.sh

Code: Select all

cd $1 => cd "$1"
now works with spaces in path names (not in zip)

Paul

Return to “General discussion”