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?

overexchange
  • 1,466
  • 10
  • 29
  • 46
  • 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](https://unix.stackexchange.com/questions/478460/how-a-non-root-user-sudo-to-another-non-root-user-without-password#comment874665_478460). – roaima Oct 29 '18 at 21:37

1 Answers1

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.

Stephen Kitt
  • 411,918
  • 54
  • 1,065
  • 1,164