Skip to content

Instantly share code, notes, and snippets.

@sharunkumar
Last active November 12, 2024 19:39
Show Gist options
  • Save sharunkumar/502cd4223cef863d86c144bd30c083c3 to your computer and use it in GitHub Desktop.
Save sharunkumar/502cd4223cef863d86c144bd30c083c3 to your computer and use it in GitHub Desktop.
Disable password prompt for your user on WSL (Ubuntu)
#!/bin/bash
# Check if the script is run with sudo privileges
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root. Please use sudo."
exit 1
fi
# Get the username of the person who invoked sudo
USER=$SUDO_USER
# Add a no-password rule for the user in sudoers
echo "$USER ALL=(ALL) NOPASSWD:ALL" | sudo tee /etc/sudoers.d/$USER >/dev/null
# Set the appropriate permissions on the file
sudo chmod 440 /etc/sudoers.d/$USER
echo "Passwordless sudo is now enabled for the user $USER."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment