How to run command as different user
su -s /bin/bash -c "/usr/bin/echo -n foo" -g apache apache
-s /bin/bash
overrides nologin and allows to interpret value of-c
option-c "/usr/bin/echo -n foo"
allows to avoid using dash-starting first argument
sudo to the rescue!
sudo -u <user> -g <group> -- echo -n foo