We were unable to load Disqus. If you are a moderator please see our troubleshooting guide.

cpss454 • 10 years ago

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.

gregf • 11 years ago

Where does runuser come from? None of my boxes seem to have it.

ScholesC • 10 years ago

god doc :)
runuser is good ...
we can use it in script
#!/sbin/runuser username

Roozbeh • 11 years ago

I often use
sudo -u USERNAME -i
or
sudo -u USERNAME -s

to switch different user and then run my commands as that user.

Jahangir Zinedine • 8 years ago

Thanks, that helped me a lot, I needed the -i switch which instructs shell to load .profile file.

Helped me start a docker instance and run a command as a different user, nothing worked except "sudo -u USERNAME -i"

M.Pasha • 8 years ago

Its really a nice article, I am trying to executing multiple command in otheruser. like example, grepping some text.

I have tried su and runuser, but failed. Any suggestion please...

runuser -l user -c 'df -h' && 'grep Filesystem'

cpss454 • 10 years ago

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)
If 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.

Prasad • 11 years ago

Best doc.

Pierre B. • 11 years ago

I personnaly use the su - -c as an administrator, but the sudo is a very handy tool for end-users when correctly configured.

Vivek Gite • 11 years ago

$ rpm -qf /sbin/runuser
coreutils-8.4-19.el6.x86_64