Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

Thanks!

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
add comment

1 Answer

up vote 1 down vote accepted

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

suds () { 
    ARGS="$@"
    /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.

Rik

share|improve this answer
add comment

Your Answer

 
discard

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.