Last active
November 12, 2024 19:39
-
-
Save sharunkumar/502cd4223cef863d86c144bd30c083c3 to your computer and use it in GitHub Desktop.
Disable password prompt for your user on WSL (Ubuntu)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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