Rio
Rio

Reputation: 783

Linux sudo to change user

How to change user by doing "su - username"

-> sudo su - origin

works

-> su - origin
Password:

asks for password

This is the settings on "sudo visudo":

Rio       ALL=(ALL)       NOPASSWD: ALL

Upvotes: 1

Views: 2226

Answers (1)

alephnil
alephnil

Reputation: 126

The first command change the user to root and then to the specified user. You type your own password to be root (not the root password or that of user origin), or if you configured it so (as you did), no password at all, and you are allowed to do this because you are allowed in the /etc/sudoers file. Then, when root, you are allowed to switch to any user because the su command allows root to switch to any user without password.

In the second command, you ask su as a normal user to switch to user origin. Then you are asked for user origin's password. The su command does not read the /etc/sudoers file, and since you are not root, you are asked for a password. In other words, the sudo is required to make it passwordless.

As a note, the su command is much older than sudo, and the normal procedure before sudo was to su to root, and then to another user, unless you knew the password of that other user.

Upvotes: 3

Related Questions