Super User is a question and answer site for computer enthusiasts and power users. 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

Possible Duplicate:
automate sudo su - user command

when the sudo su - user command gets executed inj script ,it asks for a password. i want a solution in which script automaticaaly reads password from somewhere. i dont have permission to edit sudoers file.i have the permission to store password in a file.the script should read password from that file . also expect is not installed and i do not have permission to install it on machine from where the script would be run

share|improve this question

marked as duplicate by DMA57361 Feb 9 '11 at 12:51

This question was marked as an exact duplicate of an existing question.

Please do not duplicate your own questions; if you need to you can use the edit function at the bottom of the question you have already asked to add further details. – DMA57361 Feb 9 '11 at 12:52

You can use command

 echo "your_password" | sudo -S <rest of your parameters for sudo>

(Of course without < and >)

Please note that you should protect your script from read access from unauthorized users. If you want to read password from separate file, you can use

 cat /etc/sudo_password_file | sudo -S <rest of your parameters for sudo>

(Or whatever is the name of password file, containing password and single line break.)

From sudo man page:

   -S          The -S (stdin) option causes sudo to read the password from
               the standard input instead of the terminal device.  The
               password must be followed by a newline character.
share|improve this answer

Not the answer you're looking for? Browse other questions tagged .