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

Alice has sudo rights. Bob does not (this is not changeable), but does know the password to Alice's account.

If Bob wants to perform administrative commands he must:

  1. su alice
  2. fill in Alice's password for su
  3. sudo whoami
  4. fill in Alice's sudo password
  5. command gets executed with super user rights

To shorten this I use: su -m alice -c 'sudo whoami'.

However, I want to build an alias command that replaces with this tedious command with just the regular sudo command.

So I made this: alias sudo="su -m alice -c 'sudo $@'".

2 caveats:

  • It doesn't work
  • It always asks for Alice's su password, the sudo password it does remember

How can I do this better?


share|improve this question
Aliases don't take parameters. Use a function instead. I believe su never remembers passwords. – Dennis Williamson Nov 9 '10 at 22:12
up vote 1 down vote accepted

This depends on the sudoers configuration. If "Defaults requiretty" is set this method wont work.

suds () { 
    /bin/su -m alice -c "/usr/bin/sudo  TERM=xterm $ARGS"

A few comments about this

  1. It will always ask for alices's password to authenticate the su.
  2. When a variable is offset with single quotes it will not normally be expanded.
  3. I tend to use functions rather than aliases they allow me to add a bit more logic to the transformations.
  4. This is a bad idea from a security perspective. Make sure this doesn't violate local policies before implementing it.


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.