Add to Favourites Add to Favourites    Print this Article Print this Article

Using su to run a file as a User, called by root

Say you're creating a script where you're need to run something as the User, or you're trying to debug a User cron, but the User doesn't have ssh access.   You can use "su" to execute commands as that User.

Lets say we have User
and we want to run the command        


You'd run the following as root:

/bin/su -l -s /bin/sh -c "/usr/bin/id" fred

Note that on FreeBSD, it would be:

/usr/bin/su -l -m fred -c "/usr/bin/id"



NOTE if you use any special characters like "quotes" in the command, they must be escaped with the \ character.

Was this answer helpful?

Also Read