I'll show you a way around this!
(Don't forget to read the notes on security below!)
- Start a new WSL session as you usually would.
sudo EDITOR=nano visudoand hit enter
- Use your arrow keys to scroll to the end of the file
- Append the following
username ALL=(ALL) NOPASSWD:ALLto the end of the file. Of course, replacing “username” with your user name.
- Hit CTRL + X and if asked to save, hit Y to confirm. When asked for the file name, leave the default and just hit enter.
- If you didn’t do any typos, that’s it! No more annoying password prompt inside your WSL session.
A note on security
This is the same way it’s done on a real Linux installation, and I would of course never recommend doing this on a real Linux installation for your user account.
But because in this case, this is contained within the WSL shell, I’d say it’s “okay” as long as you don’t run untrusted scripts or added dodgy repos to your WSL container. Because WSL can access all your files on your Windows side!
You should know, that this means that any script or application you run inside WSL as your user, which requests sudo, will be granted sudo privilege without password prompt. Follow this guide only if you know what you are doing.