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


Enter Your Query:
Use '%' for wildcards and quotes for "exact phrases"


Top Level » System Level

Using su to run a file as a User, called by rootLast Modified: Mar 20, 2017, 1:14 pm
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.

© 2018 JBMC Software, Suite 173  3-11 Bellerose Drive, St Albert, AB  T8N 1P7  Canada.  Mon-Fri 9AM-5PM MST