Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to automatically launch gksudo whenever I open a text file without write permissions in Nautilus? I often need to edit my /etc/hosts file and sometimes I forget to right click and select "Open as administrator".

share|improve this question
Are you looking for a solution like nautilus-gksu, which adds an "Open as administrator" item to the context menu, or are you already using it and want a way to do this without using the context menu? – htorque Jan 9 '11 at 15:56
I'm already using it. I'd like not having to right click every time as I often forget. It would be nice if it just would be the default double click action for non writeable files. – Olivier Lalonde Jan 9 '11 at 16:01
report a wishlist bug - it would be awesome to add this as a feature. – RolandiXor Jan 10 '11 at 22:23
test -w "$1" || exec $SUDO $EDITOR "$1"
exec $EDITOR "$1"

Paste that in a file, make executable, and set as default to open whatever files you like. Change the variables if you have a different editor or sudo program.. (Personally, I like gksu-polkit, from the package of the same name, better than gksudo, just because it doesn't grab my screen.)

I assume you know how to do all that; I'm more than happy to help if you don't.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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