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.
This commit is contained in:
2026-05-26 13:09:41 -04:00
parent 31a1c4089a
commit 724c631cd0
2 changed files with 17 additions and 0 deletions
+1
View File
@@ -303,6 +303,7 @@ Install method priority: **git+cargo source build** (fish) → **cargo** (other
| `screensleep` | Turn off the display via KDE PowerDevil |
| `wake-lock <cmd>` | Run a command with `systemd-inhibit` to prevent sleep |
| `swapstat` | Colorized zRAM compression ratio, swappiness, and swap priority report |
| `sudo-toggle` | Toggle sudo password bypass — writes/clears a `NOPASSWD` rule in `/etc/sudoers.d/nofail-toggle` |
| `tmux-clean` | Kill all detached tmux sessions |
| `limine-edit` | Safely edit and re-verify Limine bootloader configuration |
| `sbver` | Verify bootloader signing status for Secure Boot |
+16
View File
@@ -0,0 +1,16 @@
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