Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I run a program as nobody?

I want a user-privileged (not root) process to launch new processes as user nobody. I've tried a straight call to setuid that fails with -1 EPERM on Ubuntu 8.04:

#include <sys/types.h>
#include <unistd.h>

int main() { 
       setuid(65534);
       while (1);
       return 0;
}

How should I do this instead?

like image 432
jldugger Avatar asked Sep 15 '08 20:09

jldugger


2 Answers

You will require assistance and a lot of trust from your system administrator. Ordinary users are not able to run the executable of their choice on behalf on other users, period.

She may add your application to /etc/sudoers with proper settings and you'll be able to run it as with sudo -u nobody. This will work for both scripts and binary executables.

Another option is that she will do chown nobody and chmod +s on your binary executable and you'll be able to execute it directly. This task must be repeated each time your executable changes.

This could also work for scripts if you'll create a tiny helper executable which simply does exec("/home/you/bin/your-application"). This executable can be made suid-nobody (see above) and you may freely modify your-application.

like image 139
squadette Avatar answered Oct 07 '22 06:10

squadette


As far as I know, you can't unless you're root or have sudo set up to allow you to switch users. Or, you can have your executable have the suid bit set up on it, and have it owned by nobody. But that requires root access too.

like image 33
zigdon Avatar answered Oct 07 '22 05:10

zigdon