Stuck in a loop at login prompt after changing shell to zsh

I changed my default shell from bash to zsh and after rebooting, I am stuck in a loop where it brings me back to the login prompt after my password is entered correctly – cannot log into root either.

Because I am at the login prompt I am unable to edit anything so will need a live usb, but not sure what else to do/how to go about fixing the issue

EDIT: As requested, I log into tty1 which is there by default, I enter in my username and password as usual but when I do this it displays some text too quickly to read then goes back to the same prompt for my username again. Usually it would take me into a terminal after that where I would start xfce with startxfce4 command

To change the shell I did chsh /bin/zsh

I may have also run it as sudo, however I did this yesterday and can no longer recall if I did this or not.

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 1

On a normally-configured system, if you changed your shell with chsh, then the chosen shell is valid, so your shell is starting, but there is a problem with one of its configuration files that causes it to exit immediately.

Try pressing Ctrl+C very quickly after logging it. Depending on how loaded the machine is, the time window during which this will not kill the shell but will instruct it to stop parsing configuration files may or may not last long enough to get a realistic chance of success. Try it a few times, ideally during some heavy disk activity so that the files involved aren’t in the disk cache.

If the problem is in .zshrc, you can still log in non-interactively. This is impossible on the console, but can be done over the network:

ssh machinename 'mv .zshrc bad.zshrc'

If you have FTP (not SFTP) access, you can get rid of any configuration file this way, because FTP doesn’t read any configuration files. With SSH or SFTP, a shell is always invoked, so you won’t be able to log in if the problem is with .zprofile or .zshenv.

If you’re unable to access your account, you’ll need to fix this via the root account. If you have a root password, just log in as root on the console. If you only have access to the root account via sudo, you’ve locked yourself out, so assuming that nobody else can do it for you, you’ll need to have physical access to the machine and you’ll need to reboot it. At the bootloader prompt (you may need to press and hold Shift to make it appear), add init=/bin/sh at the end of the kernel command line (the line that starts with linux). See the Arch Wiki for more details.

Once you get access from the root account, you may either change the shell back to one that worked, or guess the file that caused the problem. Zsh reads five configuration files in /etc and 5 in your home directory.

Once you’ve recovered access to your account, if you don’t know what file caused the problem, add set -x to ~/.zshenv. This will cause zsh to print all commands before executing them. Run zsh -l to run a login shell, or log in on another terminal, and see what breaks.

Before changing your shell back to zsh, test that zsh -l works. After running chsh, check that you can log in on another terminal before logging out.

Solution 2

I was able to fix the issue by Chrooting into my computer and then changing the shell back to bash, I believe the issue came about in the first place do to a an issue with a shared library, I have resolved this issue now and shall be attempting to make zsh my shell once again, thank you all for your help.

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply