3

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,536

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
  • 434,908