2

Trying to trigger a shell script with POST request (handled by nginx). No success so far.

What I have:

exec('whoami'); // nginx

nginx:x:220:498:Nginx web server:/var/lib/nginx:/sbin/nologin

As we can see, nginx user has no shell. Could that be a problem? Next,

nginx ALL=(user) NOPASSWD: /path/to/script.sh

If I change nginx to my real user, I can run sudo -u user /path/to/script.sh without password prompt, but for some reason I'm still asked for password if I run su -s /bin/bash -c /path/to/script.sh user. Perhaps, latter invokation is somewhat more suitable for the nginx user, since he has nologin shell.

So whenever I run exec('sudo -u user /path/to/script.sh'); or run some wrapper script with that line in it through PHP - nothing happens. I can't even identify what doesn't work, since no errors are thrown.

Any help would be much appreciated.

4
  • 1
    Add 2>&1 to the end of the command to get back the error output. Also if you want to execute /bin/bash, you need that as an entry in the sudoers file. Alternatively you might want to create a wrapper script that nginx can simply execute and that can handle the sudo if it's suitable for your needs Commented Oct 21, 2014 at 8:16
  • 1
    Adding nginx to sudoers only grants it sudo privileges, not su. The two are related, in that they perform similar purposes, but nevertheless separate. Historically, sudo is a wrapper for su with additional usability features and access control mechanisms. Commented Oct 21, 2014 at 8:39
  • "No errors are thrown" is incorrect; you should find an error message in your system logs. Traditionally, sudo errors are logged to auth.log which on modern LSB systems lives in /var/log. (Now let's hope you have read access :-) Commented Oct 21, 2014 at 8:40
  • Wow, @fejese, thanks for the 2>&1. Now it immediately says sudo: sorry, you must have a tty to run sudo. Yes, I've already tried the wrapper script, which did exactly the same thing sudo -u ..., but, now, since I have errors showing, I can dig further. Commented Oct 21, 2014 at 8:41

1 Answer 1

1

Thanks to the @fejese and @triplee , I finally figured it out. I had to requiretty parameter in sudoers file, when that was changed to...

#Defaults   requiretty
#Defaults   !visiblepw

...it all went going!

Sign up to request clarification or add additional context in comments.

1 Comment

Don't forget to accept your own answer! :) Now I just have to say that its funny that your question answered my question! haha

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.