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

后端 未结 24 1268
予麋鹿
予麋鹿 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:48

    Since the OP is just development/testing, less than sleek solutions may be helpful:

    setcap can be used on a script's interpreter to grant capabilities to scripts. If setcaps on the global interpreter binary is not acceptable, make a local copy of the binary (any user can) and get root to setcap on this copy. Python2 (at least) works properly with a local copy of the interpreter in your script development tree. No suid is needed so the root user can control to what capabilities users have access.

    If you need to track system-wide updates to the interpreter, use a shell script like the following to run your script:

    #!/bin/sh
    #
    #  Watch for updates to the Python2 interpreter
    
    PRG=python_net_raw
    PRG_ORIG=/usr/bin/python2.7
    
    cmp $PRG_ORIG $PRG || {
        echo ""
        echo "***** $PRG_ORIG has been updated *****"
        echo "Run the following commands to refresh $PRG:"
        echo ""
        echo "    $ cp $PRG_ORIG $PRG"
        echo "    # setcap cap_net_raw+ep $PRG"
        echo ""
        exit
    }
    
    ./$PRG $*
    

提交回复
热议问题