Run Command as Another User Ubuntu or Linux

I like to use the su command.

Start by logging in as a sudo user or root. Let’s say you are a sudo user named michael, but another user named “web” controls files that you would like to write. You can run commands as web from your sudo user account using the su command.

Here’s an example of using the “su” command in Linux.

If I enter this command:
michael@ubutnu_server:/srv/www/$ sudo su - web
I will be switched to the “web” user in my current directory
web@ubutnu_server:~$ cd /srv/www/$