Created
April 5, 2016 18:29
-
-
Save tliron/0ddd66226eea4655328c0109bcc1bc81 to your computer and use it in GitHub Desktop.
Give Linux executables the privilege to bind to ports below 1024
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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