brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: setcap lets a program bind port 80 without root permissions

Permissions
~/tips/tip-permissions-setcap-bind-low-port

sudo setcap 'cap_net_bind_service=+ep' /usr/local/bin/myapp

Grants a program the right to open low ports without running it as root.

Running a service as root just to open port 80 is a bad trade. A file capability covers that single need.

sudo setcap 'cap_net_bind_service=+ep' /usr/local/bin/myapp
getcap /usr/local/bin/myapp

cap_net_bind_service allows binding ports below 1024 and nothing else. The capability sits on the file, so it is lost when the binary is replaced by an update, and it does not work on scripts. For a systemd service I prefer AmbientCapabilities=CAP_NET_BIND_SERVICE in the unit file, which survives updates. Verify it with getcap after every update of the program.

Further reading: capabilities manual page

More Permissions tips sudo su -s /bin/bash www-data sudo setfacl -R -d -m g:media:rwX /srv/media sudo cp -r /srv/site /srv/site.r ls -ln /srv/data newgrp media All Permissions tips (30) All topics

Link