Old question: "Removed zsh, but forgot to change shell back to bash, and now Ubuntu crashes (wsl)" Note that @steeldriver's answer works for my new question as well.

I have been trying to install zsh on my Ubuntu terminal 20.04 (wsl). I changed the shell (using chsh) to zsh, but then I removed zsh. Then I forgot to change the shell back to bash. Now Ubuntu crashes immediately after it's launched. How can I avoid that crash without an uninstall + reinstall?

  • Can you login to the root account (wsl -u root or wsl -d <distrib> -u root if you have more than one distrib)? If so, you should be able to chsh the user account from there. Feb 11, 2021 at 1:58
  • @steeldriver I ran wsl -u root and ran chsh -s $(which bash), but when I ran ubuntu, it didn't work. So yes, I could login to the "root account", but running the chsh didn't affect ubuntu.exe
    – crxyz
    Feb 11, 2021 at 2:06
  • 2
    When you're logged in as root, chsh -s $(which bash) will change root's default shell; to change a user's shell you would need chsh -s $(which bash) <username> (where <username> is replaced by the actual login name of your wsl user) Feb 11, 2021 at 2:08
  • @steeldriver Nice, it worked!
    – crxyz
    Feb 11, 2021 at 2:10
  • OK I added an answer below Feb 11, 2021 at 2:14

3 Answers 3


If you can log in to the WSL machine as root i.e. either

wsl -u root

or (if you have more than one WSL distribution)

wsl -d <distrib> -u root

where <distrib> may be obtained by running wsl -l in command prompt; then you can execute chsh for your user account from there i.e.

chsh -s /bin/bash <username>

where <username> is replaced by the actual login name of the user.

  • lol you saved me twice as I had to login to root again because there was no tmux server and it kept crashing so I had to login as root as edit my .zshrc
    – crxyz
    Jul 9, 2021 at 14:46

wsl -u root, as @steeldriver's answer suggests, is of course perfectly valid for accessing a WSL instance as root and fixing issues.

I'll throw in a few non-root options as well for future readers:

In this particular question, where the user's shell was set to Zsh, which had been uninstalled:

wsl -e bash

The -e/--exec argument launches the specified executable in place of the shell defined in /etc/passwd. Then, of course, a chsh could be issued from inside WSL.

Or we can just shortcut it entirely with:

wsl -e chsh -s /usr/bin/bash

... to directly change the shell.

Finally, for users who have made a bad edit to one of their startup files and can't launch:

wsl ~ -e bash --noprofile --norc

This will launch Bash (in the default user directory) without processing the startup files, so you can find the problem and fix it.


Boot with your install usb/dvd and mount the hard drive in the machine and edit the file /etc/shadow on it. You need to change the sde3 to the root on your drive most likely sda2 in a single drive system installed efi. I show you the procedure on a backup drive.

root@zeus-H370M:~# mount /dev/sde3 /mnt
root@zeus-H370M:~# cat /mnt/etc/passwd | grep zeus

Here I show you my file the very last part of it sets your login shell change it from the /bin/zsh that will be there back to bash like I have in my file. You would need to use sudo in front of the commands, instead of cat for the second replace it with nano. Save the file when done then use sudo reboot in the terminal to restart to your system.

The procedure on a real install is to take your install drive and boot from it on the machine as if going to do another install. Since Ubuntu lets you try it, you do that. Once at desktop you go to activities and type in Terminal to start that program when it opens you use the commands I show to mount the / partition and edit the file needed with nano. This drive to mount on single drive SATA drive machine will be /dev/sda the partitions /dev/sda1, /dev/sda2 if setup as single partition EFI install or just the /dev/sda1 for MBR single partition install. On EFI it is the 2 you need to mount for the edit of the file on MBR the 1 partition is mounted. Edit the file change it back to bash and when you reboot your machine it is whole again and you can login. If you can find the procedure to mount the drive in Windows you may be able to mount it and do the editing.

  • 1
    Uh, wdym? How do I boot my install using usb/dvd, and how do I mount the hard drive?
    – crxyz
    Feb 11, 2021 at 2:06
  • Can you give me more detailed steps? Also, I think ubuntu is on my machine (C:)
    – crxyz
    Feb 11, 2021 at 2:07
  • Should I run wsl.exe?
    – crxyz
    Feb 11, 2021 at 2:08
  • Sorry, but I don't know much about machines, or about linux
    – crxyz
    Feb 11, 2021 at 2:10

This site is temporarily in read-only mode and not accepting new answers.

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