Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. 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

It is possible to change the user within a shell script by su - newuser; but what if the newuser needs authentication. How can I provide the password within the shell script?

None of the users is root.

share|improve this question
Are you automating a non-interactive process? If so, you want sudo. Or do you want to prompt the user for a password? If so, can you assume that a user is logged in locally? – Gilles Mar 2 '12 at 22:45
up vote 2 down vote accepted

Using passwords in plain text files is not recommended. However, if no security risk is involved, create an expect script. Expect is a scripting language designed to interact with interactive shells and it is perfect for things like authentication or automation of processes that require a user to type in different things or select different options in a shell environment.

share|improve this answer

You cannot that I am aware of. You can schedule the job with cron for other users via Su. Besides you NEVER should put a wheel users password in a clear text file

share|improve this answer
very nice point! you're quite right! – All Mar 2 '12 at 7:19

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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