Run sudo command with desired user.
With the following entry in /etc/sudoers we can run all commands as root user
%susrs ALL=NOPASSWD: ALL #System Administrators
But the above configuration fails to run commands as different user with sudo.
We can understand this case with following example.
Code:
[user1@hosts1 vish]$ whoami
user1
[user1@hosts1 vish]$ sudo -u root whoami
root
[user1@hosts1 vish]$ sudo -u user2 whoami
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:
#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.
Password:
Sorry, user user1 is not allowed to execute '/usr/bin/whoami' as user2 on hosts1.fiji.ad.
With the below entry in sudoers file we can run all the commands as a specific user.
%susrs ALL=(ALL) NOPASSWD: ALL #System Administrators
Code:
[user1@hosts2 loe]$ whoami
user1
[user1@hosts2 loe]$ sudo -u root whoami
root
[user1@hosts2 loe]$ sudo -u speddi whoami
speddi
[user1@hosts2 loe]$ sudo -u user2 whoami
user2
Comments