Is there a way for non-root processes to bind to “privileged” ports on Linux?

后端 未结 24 1552
予麋鹿
予麋鹿 2020-11-22 02:04

It\'s very annoying to have this limitation on my development box, when there won\'t ever be any users other than me.

I\'m aware of the standard workarounds, but non

24条回答
  •  轮回少年
    2020-11-22 02:52

    There is also the 'djb way'. You can use this method to start your process as root running on any port under tcpserver, then it will hand control of the process to the user you specify immediately after the process starts.

    #!/bin/sh
    
    UID=$(id -u username)
    GID=$(id -g username)
    exec tcpserver -u "${UID}" -g "${GID}" -RHl0 0 port /path/to/binary &
    

    For more info, see: http://thedjbway.b0llix.net/daemontools/uidgid.html

提交回复
热议问题