Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Possible Duplicate:
How do I sudo a command in a script without being asked for a password?

I have a small script file, to run Nautilus as root. that reads:

gksu nautilus 

and it prompts for the root password.

Is there a way to automatically input my password inside the script file?

I know this is not a safe practice, I just want to know if I can do it.

share|improve this question
    
@izx Though the OP might not care and none of the answers adequately address it, this question actually covers territory not covered by that question. See my comment on the answer that directly addresses this question. –  Eliah Kagan Aug 23 '12 at 23:41
add comment

marked as duplicate by izx, Jorge Castro, jokerdino, Mitch, Uri Herrera Aug 24 '12 at 6:06

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2 Answers

up vote 1 down vote accepted

Another way of achieving the same, and one which is much safer. From terminal, run

sudo visudo

At the end of the file, add the following line:

username   ALL = (ALL) NOPASSWD: /usr/bin/nautilus

Replace username by the name of the user who is allowed to run nautilus as root without password (your username, I guess).

From now on, gksudo will not demand a password when you run

gksudo nautilus
share|improve this answer
    
MUCH more secure! Thanks! –  user10712 Aug 23 '12 at 20:05
add comment

Please do not downvote this answer. The questioner really knows and understands that this is a huge security risk, but he just wants to know a way so as to accomplish what he wants.

So, yes, it is simple:

echo login_passwd | sudo -S nautilus
share|improve this answer
    
The security risk is not the only problem with this technique. I haven't downvoted this because this is the only attempt to answer the question that was asked. But you can mangle ownership of files in your home directory by running non-trivial graphical appls like Nautilus as root using sudo directly rather than gksu/gksudo or kdesudo. If you replaced sudo -S nautilus with sudo -HS nautilus, that'd mostly solve the problem, but you'd still have the relatively minor .Xauthority issue. I don't know a full solution. –  Eliah Kagan Aug 23 '12 at 23:40
add comment

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