A caution about using runuser: Any command executed with runuser gets
placed in the background by default. This means multiple runuser
commands ran one after the other will each run in parallel. Use the -l
(minus el) option to force runuser to run the command inside a shel, and
thus wait for it to finish.
Just a tip: When issuing the runuser command I usually use the -c
option, and I always use double quotes instead of single quotes around
the command to be ran. This allows me to use single quotes within the
double-quoted command to pass a quoted argument.
For example, the following will not work because of nested single quotes:
runuser -l fred -c 'find /foo/foobar -name '*.txt''
(two single quotes at the end of the line)
This example uses double quotes and it works fine:
runuser -l fred -c "find /foo/foobar -name '*.txt'"
(a double-quote before "find", single quotes around '*.txt' and a double quote at the end of the line)
you want to know WHY this works, the shell processes command lines with
double quotes twice. The first pass lets the interpreter know that
anything within double quotes is an argument and that any single quotes
within the double qutes are to be taken literally.
I personnaly use the su - -c as an administrator, but the sudo is a very handy tool for end-users when correctly configured.
I often use
sudo -u USERNAME -i
sudo -u USERNAME -s
to switch different user and then run my commands as that user.
$ rpm -qf /sbin/runuser