I want that on my server fox user can be/change user and be user42 in a passwordless way (fox user have no password they loging with SSH keys)::

srv6:/etc# grep user42 /etc/sudoers
fox     ALL=(ALL:ALL) NOPASSWD: /bin/su user42

It work well if they do sudo su user42:

fox@srv6:~$ sudo su user42

But if I try do have a cleared shell with sudo su - user42 the NOPASSWD did not work

fox@srv6:~$ sudo su - akd
[sudo] password for fox: 

It's not gonna work because sudo su - user42 does not map to what you have granted in your rule. That rule does not contain the - dash and thus it don't map.

How about you do something like:

fox ALL=(user42) NOPASSWD: ALL

granting fox the right to do anything as user42 without password,

and then sudo -ui user42 where -i will

-i, --login Run the shell specified by the target user's password database entry as a login shell. This means that login-specific resource files such as .profile or .login will be read by the shell.

Which I believe is your desired outcome.

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.