Re: shell script how to switch users?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Use the -c option with su, and call a new script to run as that user.

In case you aren't sure about that option, use it as follows:

su user2 -c user2script.sh

If you only want to run one command as user2, you could simply insert
that command after the -c instead.

su user2 -c whoami

A side note, if the command is more than one word, you must enclose it
in quotes. For example:

su -c 'find / -name \*.c -print' user2
(obviously the order of -c command and the user is interchangeable).

Jacques B.


[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux