AUTHBIND(1)
π AUTHBIND(1) π
okay bestie, so this is the authbind page from the Debian Linux manual, and honestly? it's giving β¨least privilegeβ¨ and we're obsessed. sit down, grab a strawberry π, and let's get into it.
πΈ NAME πΈ
authbind β bind sockets to privileged ports without root. no cap. π
β¨ SYNOPSIS β¨
authbind [options] program [argument ...]
π¦ DESCRIPTION π¦
so here's the vibe: authbind lets a program that doesn't run as root (or like, shouldn't run as root, bestie, please) bind to low-numbered ports in a controlled way. very demure. very mindful. π
the thing is, you have to launch the program through authbind. like, you can't just ask nicely. authbind sets up some environment variables for you, including an LD_PRELOAD, and that's what lets the program β and any subprocesses it may run β bind to low-numbered (<512) ports, if your system is configured to allow that. π₯
π OPTIONS π
--deepβ normallyauthbindonly affects the one program it directly invokes with its special version ofbind(2). but if you pass--deep, then every program that program invokes, directly or indirectly, gets affected too β as long as they don't unset the environment variablesauthbindset up. it's giving generational trauma but make it file descriptors π«Ά--depth levelsβ makesauthbindaffect programs that arelevelsdeep in the calling graph. the default is--depth 1.
π ACCESS CONTROL π
okay so who gets to touch the low-numbered ports? that's decided by the permissions and contents of files in a config area: /etc/authbind. let's go step by step, it's a whole journey. π§
first up: /etc/authbind/byport/port gets tested. if this file is accessible for execution to the calling user β per access(2) β then binding to that port is authorised. but if the file can be seen to not exist (the existence check returns ENOENT), then we keep going and use further tests to find authorisation. otherwise? binding is not authorised, and the bind call returns with the errno value from the access(2) call, usually EACCES (Permission denied). π
secondly: if that test didn't settle it, we test /etc/authbind/byaddr/addr,port (any protocol) β or, failing that, /etc/authbind/byaddr/addr:port (IPv4 only) β in the same manner as above. here addr is as from inet_ntop, and port is the (local) TCP or UDP port number, expressed as an unsigned integer in the minimal non-zero number of digits.
thirdly, IPv6 only: because the textual representation from inet_ntop is complicated to predict, a variant of addr also gets tested β one that doesn't use the double colon abbreviation. so each 16-byte chunk is expressed in the minimal nonzero number of hex digits (i.e. with leading zeroes removed), and the chunks are separated by colons as is conventional. β¨
fourthly: if the question is still unresolved, the file /etc/authbind/byuid/uid is opened and read. if the file doesn't exist, then the binding is not authorised and bind returns EPERM (Operation not permitted, or Not owner). if it does exist, it gets searched for a line of the form:
addrmin[-addrmax],portmin[-portmax]
addr[/length],portmin[-portmax]
addr4/length:portmin,portmax
matching the request. the first form requires that the address lies in the relevant range (inclusive at both ends). the second and third forms require that the initial length bits of addr match those in the proposed bind call. the third form is only available for IPv4, since IPv6 addresses contain colons. addresses in the byuid file can be in any form acceptable to inet_pton. in all cases, the proposed port number must lie in the inclusive range specified. if such a line is found, the binding is authorised. otherwise it is not, and bind will fail with ENOENT (No such file or directory). π
if a read error occurs, or the directory/etc/authbindcannot be accessed, then not only willbindfail, but an error message will be printed tostderr. and fyi: unrecognised lines in/etc/authbind/byuid/uidfiles are silently ignored β same goes for lines whoseaddrhas non-zero bits more thanlengthfrom the top, or where someminis larger thanmax.
π EXAMPLE π
so, say uid 432 tries to bind to port 80 of address [2620:106:e002:f00f::21]. authbind would call access(2) on, in order:
/etc/authbind/byport/80
/etc/authbind/byaddr/2620:106:e002:f00f::21,80
/etc/authbind/byaddr/2620:106:e002:f00f:0:0:0:21,80
if none of these files exist, authbind will read:
/etc/authbind/byuid/432
and search for a line to permit the relevant access. examples of lines which would do so are:
2620:106:e002:f00f::21,80
::/0,80
ate. no crumbs. π
π PORTS 512-1023 π
bestie, listen to me. authorising binding to ports from 512 to 1023 inclusive is not recommended. some protocols (including some versions of NFS) authorise clients by seeing that they're using a port number in this range. so by authorising a program to be a server for such a port, you are also authorising it to impersonate the whole host for those protocols. not the vibe. π«
to make sure this isn't done by accident, if the port number requested is in the range 512-1023, authbind will expect the permission files to have an additional ! at the start of their leafname. little exclamation mark, big responsibility. β οΈ
π§ MECHANISM π§
the shared library loaded using LD_PRELOAD overrides the bind(2) system call. so when a program invoked via authbind calls bind to bind a socket to a low-numbered TCP/IP port, and if the program doesn't already have an effective uid of 0, the version of bind supplied by authbind forks and executes a setuid-root helper program. for non-TCP/IP sockets, high-numbered ports, or programs which are already root, authbind just passes the call to the original bind(2) system call, which is found using dlsym(3) with the handle RTLD_NEXT. iconic behaviour, honestly. β¨
π ERROR HANDLING π
usually the normal C error handling mechanisms apply. but specifically: if authbind cannot find the program it has been asked to execute, it will print a message to stderr and exit with code 255. π
the helper program usually reports back to the shared library with an exit status containing an errno value which encodes whether the bind was permitted and successful. this will be returned to the calling program in the usual way. π«Ά
in the case of apparent configuration or other serious errors, the library and/or the helper program may cause messages to be printed to the program's stderr, as well as returning -1 from bind.
π BUGS π
ngl, there are a few. let's be honest about them:
authbindcurrently only supports IPv4 and IPv6 sockets. programs which open other kinds of sockets will not benefit fromauthbind, but it won't get in their way. πΆ- the use of
LD_PRELOADmakes anauthbindinstallation specific to a particular C library. this version is for GNU/Linux libc6 (glibc2). authbindmay not operate correctly with multithreaded programs. it is inherently very difficult (if not impossible) to perform the kind of trickery thatauthbinddoes while preventing all undesirable interactions betweenauthbind's activities and those of (say) a threading runtime system. π΅- it is quite possible that
authbindand other programs and facilities which useLD_PRELOADmay interfere with each other, causing unpredictable behaviour or even core dumps.authbindis known sometimes not to work correctly withfakeroot, for example (even supposing it could be determined whatcorrectlymeans in this context). π₯ authbindis ineffective with setuid programs, because they do not honourLD_PRELOADreferences outside the system directories, for security reasons. (in fact, setuid programs should not honourLD_PRELOADat all.) of course a setuid-root program doesn't needauthbind, but it might be useful to apply it to programs which are setuid to another user or setgid. if the author or builder of such a program wishes it to useauthbind, they could have it load thelibauthbindlibrary explicitly rather than viaLD_PRELOAD. π€- some programs may have trouble because
authbindspawns a child processunder their feet, causing (for example) afork(2)to happen andSIGCHLDsignal to be delivered. unfortunately the Unix API does not make it possible to deal with this problem in a sane way. π - the access control configuration scheme is somewhat strange. π
πΈ FILES AND ENVIRONMENT VARIABLES πΈ
/usr/lib/authbind/libauthbind.so.1.0β the shared library whichauthbindcauses to be loaded usingLD_PRELOAD, and which actually implements the diversion ofbind(2)to an external program.LD_PRELOADβ the variable used by the dynamic linker when starting dynamically linked programs and deciding which shared libraries to load, and modified by theauthbindprogram to allow it to override the usual meaning ofbind(2).AUTHBIND_LIBβ if set, forcesauthbindto use its value as the path to the shared library to put inLD_PRELOAD, instead of the compiled-in value. in any case, unless--deepwas specified,authbindwill set this variable to the name of the library actually added toLD_PRELOAD, so that the library can find and remove the right entry. π―AUTHBIND_LEVELSβ this variable is set byauthbindto the number of levels left from the--depthor--deepoption, minus one. it is decremented during_initby the library on each program call, and the library will remove itself from theLD_PRELOADwhen it reaches zero. the special valueymeans--deepwas specified. π
π¦ SEE ALSO π¦
bind(2), authbind-helper(8), dlsym(3), ld.so(8)
π AUTHOR π
authbind and this manpage were written by Ian Jackson. they are Copyright (C)1998,2012 by him and released under the GNU General Public Licence; there is NO WARRANTY. see /usr/doc/authbind/copyright and /usr/doc/copyright/GPL for details.
that's the whole page bestie, you're so welcome. this one came from the Debian Project and it's dated 30th August 1998 β a true elder icon, still serving. go forth and bind responsibly π β¨π
π¦ where this page comes from
- debian bookworm: authbind 2.1.3
- debian trixie: authbind 2.2.0
- ubuntu jammy: authbind 2.1.3build1
- ubuntu noble: authbind 2.1.3build2
- ubuntu questing: authbind 2.2.0ubuntu1
- ubuntu resolute: authbind 2.2.0ubuntu2
- ubuntu stonking: authbind 2.2.0ubuntu2
- Copyright (C) 1998 Ian Jackson
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms