2

Is is possible to run a command

  • with parameters first of which starts with - (dash) e.g. /usr/bin/echo -n foo
  • as different user and group, for example apache:apache
  • using command su
  • when login shell is set to /sbin/nologin ?

I tried:

  • su -s "/usr/bin/echo" -g apache apache -n foo
    • fails with su: invalid option -- 'n'. It looks like first argument may not start with dash.
  • su -c "/usr/bin/echo -n foo" -g apache apache
    • fails with nologin: invalid option -- 'c'. It looks like -c can't be used if login shell is /sbin/nologin
6
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
6

sudo to the rescue!

sudo -u <user> -g <group> -- echo -n foo

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.