# Sudo Password Handling - Quick Reference\n\n## When Sudo is Required\n\nSudo password is needed when `fix_local_hosts: true` in your server configuration. This modifies:\n\n- `/etc/hosts` - Maps server hostnames to IP addresses\n- `~/.ssh/config` - Adds SSH connection shortcuts\n\n## Quick Solutions\n\n### ✅ Best: Cache Credentials First\n\n```\nsudo -v && provisioning -c server create\n```\n\nCredentials cached for 5 minutes, no prompts during operation.\n\n### ✅ Alternative: Disable Host Fixing\n\n```\n# In your settings.ncl or server config\nfix_local_hosts = false\n```\n\nNo sudo required, manual `/etc/hosts` management.\n\n### ✅ Manual: Enter Password When Prompted\n\n```\nprovisioning -c server create\n# Enter password when prompted\n# Or press CTRL-C to cancel\n```\n\n## CTRL-C Handling\n\n### CTRL-C Behavior\n\n**IMPORTANT**: Pressing CTRL-C at the sudo password prompt will interrupt the entire operation due to how Unix signals work. This is **expected\nbehavior** and cannot be caught by Nushell.\n\nWhen you press CTRL-C at the password prompt:\n\n```\nPassword: [CTRL-C]\n\nError: nu::shell::error\n  × Operation interrupted\n```\n\n**Why this happens**: SIGINT (CTRL-C) is sent to the entire process group, including Nushell itself. The signal propagates before exit code handling\ncan occur.\n\n### Graceful Handling (Non-CTRL-C Cancellation)\n\nThe system **does** handle these cases gracefully:\n\n**No password provided** (just press Enter):\n\n```\nPassword: [Enter]\n\n⚠ Operation cancelled - sudo password required but not provided\nℹ Run 'sudo -v' first to cache credentials, or run without --fix-local-hosts\n```\n\n**Wrong password 3 times**:\n\n```\nPassword: [wrong]\nPassword: [wrong]\nPassword: [wrong]\n\n⚠ Operation cancelled - sudo password required but not provided\nℹ Run 'sudo -v' first to cache credentials, or run without --fix-local-hosts\n```\n\n### Recommended Approach\n\nTo avoid password prompts entirely:\n\n```\n# Best: Pre-cache credentials (lasts 5 minutes)\nsudo -v && provisioning -c server create\n\n# Alternative: Disable host modification\n# Set fix_local_hosts = false in your server config\n```\n\n## Common Commands\n\n```\n# Cache sudo for 5 minutes\nsudo -v\n\n# Check if cached\nsudo -n true && echo "Cached" || echo "Not cached"\n\n# Create alias for convenience\nalias prvng='sudo -v && provisioning'\n\n# Use the alias\nprvng -c server create\n```\n\n## Troubleshooting\n\n| Issue | Solution |\n| ------- | ---------- |\n| "Password required" error | Run `sudo -v` first |\n| CTRL-C doesn't work cleanly | Update to latest version |\n| Too many password prompts | Set `fix_local_hosts = false` |\n| Sudo not available | Must disable `fix_local_hosts` |\n| Wrong password 3 times | Run `sudo -k` to reset, then `sudo -v` |\n\n## Environment-Specific Settings\n\n### Development (Local)\n\n```\nfix_local_hosts = true  # Convenient for local testing\n```\n\n### CI/CD (Automation)\n\n```\nfix_local_hosts = false  # No interactive prompts\n```\n\n### Production (Servers)\n\n```\nfix_local_hosts = false  # Managed by configuration management\n```\n\n## What fix_local_hosts Does\n\nWhen enabled:\n\n1. Removes old hostname entries from `/etc/hosts`\n2. Adds new hostname → IP mapping to `/etc/hosts`\n3. Adds SSH config entry to `~/.ssh/config`\n4. Removes old SSH host keys for the hostname\n\nWhen disabled:\n\n- You manually manage `/etc/hosts` entries\n- You manually manage `~/.ssh/config` entries\n- SSH to servers using IP addresses instead of hostnames\n\n## Security Note\n\nThe provisioning tool **never** stores or caches your sudo password. It only:\n\n- Checks if sudo credentials are already cached (via `sudo -n true`)\n- Detects when sudo fails due to missing credentials\n- Provides helpful error messages and exit cleanly\n\nYour sudo password timeout is controlled by the system's sudoers configuration (default: 5 minutes).
