2

On RHEL 7.5, I created a non-root user and would like to switch from one non-root-user to another non-root-user, without password.

First tried, sudo -u user1, command syntax error

then tried, sudo su - user1, asks for passwd,

1) Why it asks for password?

2) How sudo -su user1 different from sudo su - user1?

  • Being able to switch from one non-root user to another without a password would be a massive security hole; I'm pretty sure it's not possible (at least, without special configuration to allow it e.g. changing /etc/sudoers). – Gordon Davisson Oct 29 '18 at 19:07
  • Possibly related context. – roaima Oct 29 '18 at 21:37
3
  1. I’m guessing sudo su - user1 asks for a password because sudo is configured to ask for a password to switch to root.

  2. sudo su - user1 switches to root (if sudo allows it) and runs su - user1, which switches to user1. sudo -su user1 runs a shell as user1. In the first case, su is a command, run by sudo; in the second, it’s the two options -s and -u given to the sudo command.

sudo -u user1 fails because you’ve told sudo to do something as user1, but you haven’t told it what; you need to specify a command to run, or -s to start a shell.

See su vs sudo -s vs sudo -i vs sudo bash for a more general discussion.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.