1

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.

StanP
  • 201
  • 1
  • 2
  • 5
  • @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](http://askubuntu.com/questions/155791/how-do-i-sudo-a-command-in-my-python-script-without-being-asked-for-a-password). See [my comment on the answer that directly addresses this question](http://askubuntu.com/questions/179472/how-to-create-a-script-file-to-input-password#comment223225_179474). – Eliah Kagan Aug 23 '12 at 23:41

2 Answers2

2

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
hytromo
  • 4,904
  • 3
  • 33
  • 63
  • *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`](https://help.ubuntu.com/community/RootSudo#Graphical_sudo). 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
1

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
January
  • 35,223
  • 15
  • 82
  • 101