23.9 C

Run Command as Other Users on Linux

In Linux, there are a number of situations where running a certain command as another user is necessary. It’s especially true in the professional/enterprise environment where there are a number of users. This method is also useful if one user doesn’t have any particular shells.

Running command

For performing the action, you have to follow the following structure –

su -s <shell_path> <user_name> -c <command>

For example, I have Apache installed and there’s a PHP file at the location “/var/www/html”. In order to run the file as user “viktor”, the following command will be necessary –

- Advertisement -
su -s /bin/sh viktor -c "/usr/bin/php /var/www/html/php_demo.php"


- Advertisement -
Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
"The best Linux newsletter on the web"


Please enter your comment!
Please enter your name here

Latest article