How to open a file in ranger as root?

8

3

How do I open a file in the file-manager "ranger" with superuser rights?

While ":open_with vim" opens the file as none root with vim, I am looking for something like ":open_with sudo vim", but that does not work.

PatrickSteiner

Posted 2017-07-23T13:19:04.527

Reputation: 185

Answers

10

According to man:

Flags give you a way to modify the behavior of the spawned process. They are used in the commands ":open_with" (key "r") and ":shell" (key "!").

   f   Fork the process.  (Run in background)
   c   Run the current file only, instead of the selection
   r   Run application with root privilege (requires sudo)
   t   Run application in a new terminal window

In your case you would need to use :open_with r vim

Artalus

Posted 2017-07-23T13:19:04.527

Reputation: 291

:open_with r vim worked fine for me, thanks a lot! – PatrickSteiner – 2017-07-27T05:43:09.737

Thanks. For me the following commands only works by change order => :open_with vim r – DhineshYes – 2020-02-24T08:02:38.090

0

I usually open my file manager from a root terminal by simply typing in the program name with no parameters e.g.

root@machine: thunar

This will open the file manager as a root user and then anything I open to edit from the file manager is opened as the root user.

Or, if the file is easy to navigate to or name in the terminal such as "FSTAB" I just open my text editor with the named file such as

root@machine: mousepad /etc/fstab.

Further, if it an easy change, I simply use my terminal editor as a root user (nano in my case).

Damon

Posted 2017-07-23T13:19:04.527

Reputation: 1 789

2Starting a file manager from root terminal is a rather risky option IMO, since you can then delete and edit virtually anything without any warnings. Especially if the FM doesn't give you any clue that it was started from under root and you forget about it later! – Artalus – 2017-07-24T19:40:15.793

@Artalus Good call. I can admit I am not a system admin for more than our own business and I open a small fraction of config files that a real admin does so I can have a lower proficiency and still make less total number of mistakes than a real admin and still work on the wild side. It also helps we have VMs both mirrored and backed up. – Damon – 2017-07-24T23:08:32.153