Sudo: Running as a specific user

Sudo is usually used to allow a user to run commands as root, but what happens if you want a user to run a command as another user?

You can use the example below to configure your sudo rule.


[[email protected] ~]$ sudo -u sudoguy whoami  

The rule from /etc/sudoers:

bcane ALL=(sudoguy) /usr/bin/whoami, NOPASSWD: ALL

Same thing but instead of bcane the users group:

%users ALL=(sudoguy) /usr/bin/whoami, NOPASSWD: ALL
Benjamin Cane
Principal Engineer, Vice President

Benjamin Cane is Principal Engineer at American Express. He has more than 16 years of experience with roles in both systems and software engineering. He leverages both his systems and software skills to build end-to-end platforms. Platforms, purpose built for performance and resiliency. Benjamin is also the author of Red Hat Enterprise Linux - Troubleshooting Guide (2015, Packt Publishing), and he has published many popular articles on topics such as Linux, Docker, Python, Go and Performance Tuning. Thoughts and Opinions expressed in my articles are my own.