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.


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

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

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