how do i claim a low-numbered port as non-root the "right way"

Posted by qbxk on Stack Overflow See other posts from Stack Overflow or by qbxk
Published on 2010-04-04T12:19:09Z Indexed on 2010/04/04 12:23 UTC
Read the original article Hit count: 314

Filed under:
|
|
|
|

I have a script that I want to run as a daemon listening on a low-numbered port (< 1024)

Script is in python, though answers in perl are also acceptable.

The script is being daemonized using start-stop-daemon in a startup script, which may complicate the answer

What I really (think) don't want is to type ps -few and see this process running with a "root" on it's line.

How do I do it?

( from my less-than-fully-educated-about-system-calls perspective, I can see 3 avenues,

  1. Run the script as root (no --user/--group/--chuid to start-stop-daemon), and have it de-escalate it's user after it claims the port
  2. Setuid root on the script (chmod u+s), and run the script as the running user, (via --user/--group/--chuid to start-stop-daemon, the startup script still has to be called as root), in the script, acquire root privileges, claim the port, and then revert back to normal user
  3. something else i'm unaware of

)

© Stack Overflow or respective owner

Related posts about linux

Related posts about setuid