6

I want to be able to quickly open a new window of Pantheon Files with root to do administrative tasks (e.g. edit .desktop files). So when I right-click on a folder icon it would be nice to have an option to "Open folder as root" similar to the already present "Open in Terminal".

  • My only suggestion would be to right-click and open in terminal, and do any root work there. – Lewis Goddard Jun 30 '15 at 21:10
  • 1
    Required: Do NOT edit things as root unless you are sure you know what you are doing, and not just following instructions off the internet. – Lewis Goddard Jun 30 '15 at 21:11
  • unix.stackexchange.com/q/92494/32012 – user170 Jul 13 '15 at 17:56
  • @Tim As far as I remember the question actually got downvoted before I added the disclaimer... – quassy Jul 13 '15 at 18:26
  • Disagree. It's not their fault, this site should appeal to all demographics, hence newbies should be warned. And also reminded that there might be better / securer / easier ways to achieve what they aim to do. – quassy Jul 13 '15 at 18:29
6

It is already there for me in the dock:

However, if you can't see that, use sudo:

sudo -i pantheon-files

You want to be able to jump to a sudo instance of the current folder. It's a little roundabout, but you could right click, open in terminal:

Then run this command:

sudo -i pantheon-files $(pwd)

you could even set up an alias for it.

  • 1
    Thanks for the answer, also helpful. But I would like to have a direct link in "Open in >", which should be possible with a file in /usr/share/contractor (but I'm not sure what to actually put there because gksu is deprecated). – quassy Jun 30 '15 at 22:17
  • 1
    You can take pkexec instead of gksu. – tim2611 Jul 1 '15 at 9:04
  • 1
    @DanielForé what do you mean by secure? 2 months ago, sudo -i was the recommended method... – user3 Jul 13 '15 at 17:44
  • 2
    @DanielForé What makes you claim that sudo is “not as secure as pkexec”? You've said that gksudo was deprecated (so is it just gksudo or also sudo that you don't like), and you quote a passage from the pkexec documentation which doesn't seem relevant since sudo has the same feature. – Gilles 'SO- stop being evil' Jul 13 '15 at 19:12
  • 2
    @Gilles, Tim we have a policykit policy written for Files already to run it using pkexec. In the interest of not mucking up the comments here, perhaps this should be its own new question. It's not about "liking" anything. gksu is deprecated upstream by its own developers. From polkit docs "In contrast to systems such as sudo, it does not grant root permission to an entire process, but rather allows a finer level of control of centralized system policy." You don't jump straight to sudo, just to a "user" that has higher filesystem permissions. It doesn't grant the app other sudo rights. – Daniel Foré Jul 13 '15 at 20:36
6

We need to create a .contract file in /usr/share/contractor.

Run these two commands:

sudo touch /usr/share/contractor/openasroot.contract
sudo nano /usr/share/contractor/openasroot.contract

Then paste in the following:

[Contractor Entry]
Name=Open folder as root
Icon=pantheon-files
Description=Open current folder as root privilege
MimeType=inode;
Exec=gksudo pantheon-files
Gettext-Domain=pantheon-files

Source


Just a reminder, be careful when you have root access - bad bad things can happen.

  • 3
    pkexec panthen-files works in the terminal, but it doesn't work in a .contract... at least for me – Rafael Jul 13 '15 at 18:58
  • That's probably the reason why elementary OS is using the shellscript /usr/bin/pantheon-files-pkexec for New Window As Administrator – Rafael Jul 13 '15 at 19:04
  • 1
    /usr/bin/pantheon-files-pkexec doesn't process any arguments, that's why it doesn't work properly in a .contract. Modifying pantheon-files-pkexec to accept arguments or, better, creating a new script might solve this problem. – Rafael Jul 13 '15 at 19:14
  • Related bug report: #1474124 pantheon-files-pkexec does not accept arguments (old link was broken). Not marking as accepted because there seems to be no safe & working solution right now... – quassy Jul 29 '15 at 20:57
0

This script works on elementary OS Loki to add "Open folder as root" option via pkexec.

To use it, first create a contractor entry:

sudo touch /usr/share/contractor/folder-openasroot.contract
gksudo scratch-text-editor /usr/share/contractor/folder-openasroot.contract

Then edit it like this:

[Contractor Entry]  
Name=Open folder as root  
Icon=pantheon-files  
Description=Open folder as root  
MimeType=inode;  
Exec=pantheon-files-pkexec %U  
Gettext-Domain=pantheon-files  

And then via terminal run this command:

sudo sh -c 'echo "#!/bin/sh
pkexec \"/usr/bin/pantheon-files\" \"\$@\"" > /usr/bin/pantheon-files-pkexec'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.