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

I have access to another user's account using command:

sudo su - other_user

I do not have enter password. It seems that this is the only command that sudo allows me.

After that I'm able to perform several tasks like file copying and server restarting. I would like to automate those tasks so that a script can be executed by me, which would get other_user's rights and do what it has to do. However, sudo spawns another shell, which until I exit it blocks script execution. Is it possible to control that shell and to send commands into it from my script?

Update 2011-11-01:

I tried suggestions from the answers and both these commands:

sudo -u other_user whoami
sudo su - other_user -c "whoami"

ask for password.

Unfortunately, I could not find sudoers to look at settings. The situation annoys me a bit because a have privileges to do what I want to, but can't automate that.

share|improve this question

Use the -coption of the su command to execute commands as another user.
If needed, you can also use the output of those commands in your script, or in your shell.


[infeligo@server ~] cat /home/kenny/secretfile.txt  
cat: /home/kenny/secretfile.txt: Permission denied  
[infeligo@server ~] sudo su - kenny -c "cat /home/kenny/secretfile.txt"  
Dear diary: Today was a boring day at work. Good thing it's a friday!  
[infeligo@server ~]
share|improve this answer

The use of su is not entirely necessary.

$ sudo -u other_user whoami
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.