1

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!

FLX
  • 141
  • 8

1 Answers1

1

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

Rik Schneider
  • 2,479
  • 14
  • 19