1

Via Apps (add/remove programs), I've removed WSL. I just found Windows Subsystem Linux in the list and clicked "uninstall".

When I go to cmd and type "bash", it puts me in Debian.

For some reason. Is this preventing me from accessing my WSL installation of Debian?

I use wsl --install --distribution Debian and end up with a version of Debian that won't start. If I type wsl in cmd, it just goes directly back to cmd:

Prompt: user typed WSL; Prompt; user typed WSL again; Prompt...

If I type Debian, same thing.

But if I type bash, I get kicked into a Debian install where I cannot change my root password and have forgotten my root password.

If someone knows how to reset the root password, let me know. Of course, wsl ~ -u root -e chsh gives me a password prompt, but I don't know the password so that's useless.

Also note: I cannot figure out how to uninstall the wsl that I'm getting kicked into when I type wsl ~ -e chsh. Maybe I could reinstall that one since I can at least enter it.

3
  • 1
    You can't reset root on Linux without the ability to go into a boot mode that doesn't exist with WSL. If your user is in the sudo group then you could in theory replace the password hash for root. I assume you have tried wsl --unregister Debian before trying to reinstall Debian?
    – Ramhound
    Commented Apr 6, 2023 at 0:16
  • @Ramhound It's not advisable (see my answer for why), but it is possible to set or reset a root password on WSL with wsl -u root -e passwd. Commented Apr 7, 2023 at 19:22
  • @NotTheDr01ds You need the root password for that to work. I think it's not possible to use admin priv in Windows to change the Debian WSL password: I wish I could force this to be possible. Instead, I am going to start using KeePass and just accept that my memory is twack. Commented Apr 14, 2023 at 3:45

1 Answer 1

2

There are quite a few things going on there ;-).

Via Apps (add/remove programs), I've removed WSL. I just found Windows Subsystem Linux in the list and clicked "uninstall".

When I go to cmd and type "bash", it puts me in Debian.

It's a bit of an odd situation, at least on Windows 10. This occurs because there are actually two installations of WSL:

  • The first is what's called the "in box" version of WSL. Up until recently, this was the only WSL. It's shipped with Windows and enabled in the Turn Windows Features on or off settings. Under Windows 10 (but not Windows 11), it's actually required as a dependency of the other version ...

  • Which is the application package version of WSL. This is now the primary way to install WSL, and when you uninstalled it from the Add or remove programs settings, this is what was removed. After it was removed, however, the older version still remained (and took over).

Neither of these is the Debian WSL distribution itself. That's a separate installation. Confused yet? ;-)

So you really should reinstall WSL from the Microsoft Store to make sure you have the latest.

I use wsl --install --distribution Debian and end up with a version of Debian that won't start. If I type wsl in cmd, it just goes directly back to cmd:

If I type Debian, same thing.

But if I type bash, I get kicked into a Debian install

That is odd - wsl and bash should do the same thing, just with the wsl command providing more options. However, the bash command is deprecated in WSL, so I can't say for sure what's happening here.

A wsl -l -v might show more than one distribution installed, but even that wouldn't account for exactly what you are seeing.

If you really do want to uninstall a distribution, as @Ramhound mentioned in the comments, you can use:

wsl --unregister <distro>

where I cannot change my root password and have forgotten my root password.

If someone knows how to reset the root password, let me know. Of course, wsl ~ -u root -e chsh gives me a password prompt, but I don't know the password so that's useless.

It sounds like you are looking for the passwd command rather than chsh. The former changes the password, the later the default shell for a user.

That said, there is no initial password for root in most Linux distributions nowadays. Your initial non-root user should be added to sudoers (again by default, even when not using WSL). This is something that the WSL distribution installers do for you. Having a root password is considered a bad security practice, since it gives root the ability to login without accountability or logging.

If you need to reset your user password (so that you can sudo), you can do that quite easily from PowerShell:

wsl -l -v # Confirm distribution name
wsl ~ -u root -d <distro> -e passwd <username>

If you don't know the default username, it's usually UID 1000, so you can find it (again from PowerShell) with:

wsl id -un 1000

Again, add the -d <distro> if needed.

Of course, wsl ~ -u root -e chsh gives me a password prompt, but I don't know the password so that's useless.

I will say that's odd, though. chsh as a root user doesn't ask for a password on my Debian installation under WSL. That's the case even if I (pathologically) set a root password.

1
  • Okay. I did re-install (not for the reasons mentioned although they are very informative; rather, because a new Debian instance appeared in add-remove programs after restart). I also had to switch to WSL v1 (not sure why v2 doesn't work on my system anymore). I had trouble setting the initial root password (you have to login as root and then type passwd rather than using su - root because that requires a password and a blank password does not work). So, a lot of interesting things going on, but steps are being taken. I think your answer will work for most people. Thank you very much! Commented Apr 16, 2023 at 4:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .