[sudo-users] Passing password to sudo

Todd C. Miller Todd.Miller at courtesan.com
Thu Apr 23 09:46:38 EDT 2009


In message <49EE3A7D.7020702 at filemaker.com>
	so spake Alex Chen (alex_chen):

> Is there a way to invoke sudo so that the password can be passed as a 
> command line parameter instead of manually typing in?
> We want to use 'sudo' to execute scripts under certain user's name 
> programmatically, e.g. launch sudo via 'exec', and pass the user's password
> directly to sudo non-interactively.
> 
> We looked at the sudo man page but could not find anything that allows 
> us to do so.

No, because the password would be visible to anyone in a ps listing.
However, you can send the password to sudo's standard input with
the -S flag.  Note that since you won't know whether sudo needs a
password or not you probably need to use the -k flag first to clear
any existing timestamp.

You might be better off just allowing the user in question to run
those scripts without a password using the NOPASSWD tag.

 - todd



More information about the sudo-users mailing list