NOTE :I hope this procedure applies to pretty much every distribution of Linux. If you don't see it working, let me know.

Today i tried to change the login shell (from zsh) for my Arch Linux using this syntax

chsh -s /usr/bin/bash

When i changed it to sh and rebooted, i am unable to login. It repeatedly says that 'the password is incorrect' , though for sure i know the password is right.  Then i suspected that there could be issues with the login shell i just changed and it turned out so. Now i have to either set the login shell back to /bin/bash or boot through another way, and i hoped there should be some way in grub to achieve it, and started to explore., i tried to boot grub single user mode, and it also didn't help as it requires a valid shell to login. Then i found this option in grub arch documentation i.e

init=/bin/sh

which will boot the kernel and launch the mentioned shell (for that boot alone). For sure i know /bin/sh exists with any Linux distro and i used it. Here are the steps to follow.

  1. Boot system
  2. When the grub menu shows up (press 'e')
  3. It will show a small Emacs like editor window and from the window you can see a list of statements executed by grub.
  4. From the list of statements find the line that starts with 'linux'. and at the end of that line append init=/bin/sh . You are basically adding extra parameter to the Linux kernal, from the boot loader.  I use GRUB as my boot loader. Even if you are using other bootloader's this should hold true as the parameter is specific to the kernel.
  5. Finally press "F10" to continue booting with the mentioned parameters. Now you will be booted and the sh prompt will appear. There you can set the appropriate prompt using the chsh command and continue.
  6. The parameter you added will not be there for the next boot, so you don't have to worry about your usual stuff.

If you want to understand why did chsh fail in my case, you can continue.

That's pretty vague, but i will try to explain. When you install a shell program in linux, its corresponding path is added to the file /etc/shells, which will be always checked when we try to do chsh. In my case when bash is installed along with arch Linux it put an entry as /bin/bash in that file. But after that arch Linux's installation simlink'ed /bin to /usr/bin. So whenever i enter "which bash" it returns /usr/bin/bash. I used this path to change the shell but since it's not in /etc/shells the login fails with a not so friendly error "invalid password :-(".  So the best way before changing a shell is to do the following.

  1. In the prompt enter chsh -l
  2. This will list all the shells and their corresponding path. Make sure you enter from one of them. This way you don't get into wierd problems .

Thanks

Soundararajan