With sudo, it is possible to execute a command as an other user and really safely pass arguments to that command.
Example nasty argument:
nastyArg='"double quoted" `whoami` $(whoami) '"'simple quoted "'$(whoami)'"'" Expected output, run via a termninal as congelli501:
% echo "$nastyArg" "double quoted" `whoami` $(whoami) 'simple quoted $(whoami)' Execute as congelli501, via sudo:
# sudo -u congelli501 -- echo "$nastyArg" "double quoted" `whoami` $(whoami) 'simple quoted $(whoami)' Execute as congelli501, via su (usual escape method):
# su congelli501 -c "echo '$nastyArg'" "double quoted" `whoami` $(whoami) simple quoted congelli501 As you can see, the argument is not safely passed as it is re-interpreted by a shell.
Is there a way to launch a command via su and pass its arguments directly, as you can do with sudo ?