How To: run / execute a command as a given / specific user in Linux / Debian / Ubuntu / Kali Linux / RHEL / CentOS etc. in a terminal / command line

In this method, we will need to enter the password of the current user.

sudo -u <anotherUser> <commands>
sudo -u <anotherUser> mkdir /tmp/test

Switch to given / specific user to run command (su -u )

In this method, we will need to enter a password for this / specified user.

su -u <anotherUser> <commands>
su -u anotherUser mkdir /tmp/test
Sidebar