in reply to How to run a perl script under "nobody" user?

You can use sudo to start a script under a different user (but you either need root powers, or sudo has to be configured to allow that).

Replies are listed 'Best First'.
Re^2: How to run a perl script under "nobody" user?
by sunshine_august (Scribe) on Nov 19, 2008 at 10:23 UTC
    I try to do this, but faild:
    [root@localhost]# su - nobody -c "./foo.pl" This account is currently not available.
      That's not a perl problem anymore, I'll try anyway...

      Probably the user nobody has the program /usr/sbin/nologin as its login shell, which prints the message you have quoted and then exits.

      Possible solutions are (1) use sudo as I suggested, not su (2) convince su not to spawn a login shell (no - in the command line) or (3) give the user nobody a different login shell.

        What I really want is the script can run under "nobody" user like the Apache way.

        We usually start apache like this:

        sudo /usr/local/apache2/bin/apachectl start
        then, when we `ps aux | grep apache`, we can find that apache's user id is "nobody":
        root 1102 0.3 0.2 5972 2368 ? Ss 18:35 0:00 /usr/ +local/apache2/bin/httpd -k start root 1103 0.0 0.0 1620 300 ? S 18:35 0:00 /usr/ +bin/cronolog /usr/local/apache2/logs/access_%Y-%m-%d-%H-%M.log nobody 1109 0.0 0.1 5972 1496 ? S 18:35 0:00 /usr +/local/apache2/bin/httpd -k start nobody 1110 0.0 0.1 5972 1496 ? S 18:35 0:00 /usr +/local/apache2/bin/httpd -k start nobody 1111 0.0 0.1 5972 1496 ? S 18:35 0:00 /usr +/local/apache2/bin/httpd -k start nobody 1112 0.0 0.1 5972 1496 ? S 18:35 0:00 /usr +/local/apache2/bin/httpd -k start nobody 1113 0.0 0.1 5972 1496 ? S 18:35 0:00 /usr +/local/apache2/bin/httpd -k start

        How can I make my perl script like this?