I've recently found the need to elevate an app to a higher privilege level in order to bind()
to a port < 1024.
I've been running it with sudo
, which is fine for internal testing, but deploying it running as root is generally a very bad idea.
I've heard of setuid root, but when I looked at the source code for lighthttpd
for example it shows:
#ifdef HAVE_GETUID
if (!i_am_root && issetugid()) {
/* we are setuid-root */
log_error_write(srv, __FILE__, __LINE__, "s",
"Are you nuts ? Don't apply a SUID bit to this binary");
server_free(srv);
return -1;
}
#endif
What then is the generally accepted method to allow binding to a privileged port? I only need higher privilege for bind. After that it can be running as a normal user.
These are the ones I've heard of, but doesn't seem to be what most software is using which is why I'm asking this question.
- setuid - root
- setcap