Files
fish-config/functions/sudo-toggle.fish
T
rootiest 724c631cd0 feat(system): add sudo-toggle function
Toggles sudo password enforcement on/off by writing or
truncating a NOPASSWD rule in /etc/sudoers.d/nofail-toggle.
Useful for temporarily bypassing FIDO key prompts during
batch admin tasks without permanently weakening sudoers.
2026-05-26 13:09:41 -04:00

17 lines
916 B
Fish

function sudo-toggle --description 'Toggle sudo password requirement on/off'
# Check the file size using sudo stat to see if our bypass rule is active
set -l file_size (sudo stat -c %s /etc/sudoers.d/nofail-toggle 2>/dev/null)
if test -n "$file_size"; and test "$file_size" -gt 0
# 1. Toggle is currently OFF (Bypass is active). We want to turn security back ON.
# We use 'sudo -k' to clear the execution cache so it locks down instantly.
sudo -k truncate -s 0 /etc/sudoers.d/nofail-toggle
echo "🔒 Sudo security: ENABLED (FIDO Key required)"
else
# 2. Toggle is currently ON (Security active). We want to BYPASS it.
# We write a high-priority user-specific NOPASSWD rule.
echo "$USER ALL=(ALL:ALL) NOPASSWD:ALL" | sudo tee /etc/sudoers.d/nofail-toggle > /dev/null
echo "🔓 Sudo security: DISABLED (Bypass active)"
end
end