Root

如何讓 tcpsvd 放棄其 root 權限?

  • September 26, 2013

假設腳本在啟動時以 root 身份執行。我想從這個腳本開始tcpsvd -E 0 515 lpd。我想tcpsvd以非特權使用者身份執行。但是它需要root權限才能綁定到埠515。我該如何實現呢?

此外,我必須使用busybox tcpsvd

tcpsvd
tcpsvd [-hEv] [-c N] [-C N[:MSG]] [-b N] [-u USER] [-l NAME] IP PORT PROG

Create TCP socket, bind to IP:PORT and listen for incoming connection.
Run PROG for each connection.

   IP              IP to listen on. '0' = all
   PORT            Port to listen on
   PROG [ARGS]     Program to run
   -l NAME         Local hostname (else looks up local hostname in DNS)
   -u USER[:GRP]   Change to user/group after bind
   -c N            Handle up to N connections simultaneously
   -b N            Allow a backlog of approximately N TCP SYNs
   -C N[:MSG]      Allow only up to N connections from the same IP
                   New connections from this IP address are closed
                   immediately. MSG is written to the peer before close
   -h              Look up peer's hostname
   -E              Do not set up environment variables
   -v              Verbose

您需要在以 root 身份執行時將程序綁定到埠,然後切換到您的非特權使用者。 tcpsvd提供-u執行此操作的選項:

-u user[:group]
         drop permissions.  Switch user ID to user’s UID, and group ID to
         user’s primary GID after creating and binding to the socket.  If
         user  is  followed  by a colon and a group name, the group ID is
         switched to the GID of group instead.  All supplementary  groups
         are removed.

引用自:https://unix.stackexchange.com/questions/92532