Skip to content

Instantly share code, notes, and snippets.

@tliron
Created April 5, 2016 18:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tliron/0ddd66226eea4655328c0109bcc1bc81 to your computer and use it in GitHub Desktop.
Save tliron/0ddd66226eea4655328c0109bcc1bc81 to your computer and use it in GitHub Desktop.
Give Linux executables the privilege to bind to ports below 1024
#!/bin/bash
if (( $# != 2 )); then
echo 'Control whether an executable has the privilege to bind to ports < 1024, even if the user is not root'
echo
echo "Usage: $(basename "$0") [enable|disable|status] [path-to-exectuable]"
exit 1
fi
FILE=$(readlink -f "$2")
case "$1" in
enable)
sudo setcap 'cap_net_bind_service=+ep' "$FILE"
;;
disable)
sudo setcap 'cap_net_bind_service=-ep' "$FILE"
;;
status)
getcap "$FILE" | grep 'cap_net_bind_service+ep' &> /dev/null
if [ $? == 0 ]; then
echo 'enabled'
else
echo 'disabled'
fi
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment