5

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?

5
  • 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 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! Feb 11, 2021 at 2:10
  • OK I added an answer below Feb 11, 2021 at 2:14

2 Answers 2

14

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.

1
  • 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 Jul 9, 2021 at 14:46
0

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
zeus:x:1000:1000:Zeus,,,:/home/zeus:/bin/bash

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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.