/errors/ufw/you-need-to-be-root-to-run-this-script
ufw: ERROR: You need to be root to run this script
The commands on this page have not been executed by our verification runner yet.updated
- tool
- ufw
- exit code
- 1
- versions
- ufw 0.36
- os
- linux
ERROR: You need to be root to run this script is ufw refusing to run because the effective user is not root. ufw manages iptables/nftables rules and reads its configuration in /etc/ufw and /lib/ufw, all of which need root, so even ufw status fails without privileges. Run it with sudo: sudo ufw status verbose.
Fix
sudo ufw status verbose
sudo ufw allow 22/tcp
sudo ufw enableIn a script that may run as a normal user, check first:
if [ "$(id -u)" -ne 0 ]; then
echo "run as root (sudo $0)" >&2
exit 1
fi
ufw --force enable--force skips the interactive "Command may disrupt existing ssh connections. Proceed with operation (y|n)?" prompt, which scripts cannot answer.
Allow one user to run ufw only
# /etc/sudoers.d/ufw (edit with: sudo visudo -f /etc/sudoers.d/ufw)
deploy ALL=(root) NOPASSWD: /usr/sbin/ufwThe user then runs sudo ufw ... without a password and without getting general root access.
Sources
Related pages
errors · ufwufw: ERROR: Could not find a profile matching 'Nginx Full'ufw cannot find the app profile: the package that ships it, such as Ubuntu nginx, is not installed or the name differs. Check ufw app list, or allow 80,443/tcp.cheat sheets · ufwufw cheat sheet: enable, allow, deny, delete and route rulesufw cheat sheet: enable safely over SSH, set default policies, allow, deny, limit and delete rules, route rules, app profiles, logging and the Docker caveat.errors · iptablesiptables: Permission denied (you must be root)iptables needs root or CAP_NET_ADMIN to read or change rules. Run it with sudo; in Docker or Kubernetes add the NET_ADMIN capability, not privileged mode.