Server Fault is a question and answer site for system and network administrators. 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

There are several admin-like accounts in our Linux server, different account for different purpose.

Sometimes, there need multi-account co-work to finish a job. Manually, I can login and type the commands. But How can I make it into a single script (BASH)?

BTW: sudo didn't work on my server

share|improve this question
Why did sudo not work? What errors you get? – Zoredache Jan 11 '12 at 5:37
I have no root privilege. So I don't think I can use su. I can su to other account. But sudo will give me an password error message (password correct for su), and I don't know why. ALL account are NIS based, not local. – valpa Jan 11 '12 at 7:11

Your question is a bit unclear. But I believe you are asking how you can run commands that must be performed with other accounts.

Simply do something like this.


# execute blah as username, assuming the main script is running as root
su username -c blah

# execute blah as username, assumes you have delegated calling users permissions to run command as username
sudo -u username blah

# execute blah as username, using key-based authentication.
ssh username@localhost blah
share|improve this answer
I will try ssh. – valpa Jan 11 '12 at 7:14
Your other option may be to do something with expect. – Zoredache Jan 11 '12 at 7:25

You must use su -c command to run commands as another user. It will prompt interactively for the password. If you need to run it in batch mode you can use expect.

share|improve this answer

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.