5

I am trying to change my default shell to zsh. I have the entry placed correctly in /etc/shells file.

Each attempt I have made with this command has ended with the same error message:

chsh -s $(which zsh)
Password: ### after entering the correct password
chsh: PAM: Authentication failure

sudo chsh -s $(which zsh) ## yields the same result

I have used sudo for other commands to be sure it was not a password failure, and every other command has worked but nothing works with "chsh".

Totally stumped.

Additional information:

I have appended a line per Oli's suggested code to the /etc/shells file.

echo $SHELL 
/bin/bash

sudo chsh -s /usr/local/bin/zsh
Password:
chsh: PAM: Authentication failure

chsh -s /usr/local/bin/zsh
You may not change the shell for 'username'

Still cannot change shell.

RCF
  • 2,127

4 Answers4

7

PAM has a pretty tight hold on chsh. As you can see form /etc/pam.d/chsh, it's doing a check:

# This will not allow a user to change their shell unless
# their current one is listed in /etc/shells. This keeps
# accounts with special shells from changing them.
auth       required   pam_shells.so

There's also a man page for this check (man pam_shells) which tells us the following:

pam_shells is a PAM module that only allows access to the  system if the users shell is 
listed in /etc/shells.

It also checks if /etc/shells is a plain file and not world writable.

So by the sounds of it, you don't have a /usr/bin/zsh line in /etc/shells. Let's add one:

echo $(which zsh) | sudo tee -a /etc/shells
chsh -s $(which zsh)

Either that or your current shell isn't listed on there. If you're stuck on something like rbash, that might not be a listed example and that might stop you from changing shell.

I tested (removed the zsh line from /etc/shells, loaded zsh and tried to chsh) but saw a very different error message:

You may not change the shell for 'oli'

So it's probably not this.

Oli
  • 299,380
0

In my case the problem was my user was created with no shell (no shell in passwd file for my user). I had to change the shell as root.

Juan
  • 1
0

To complement Oli's excellent explanation with a simple fix for the You may not change the shell for 'username' error, courtesy of this answer:

# Set the shell for the current user to '/bin/bash' in this example,
# which works even if the current shell is (unexpectedly) not listed in '/etc/shells'.
sudo usermod --shell /bin/bash $USER
mklement0
  • 257
  • 2
  • 7
0

situation on my home machine was /etc/shells had not only multiple entries of /usr/bin/zsh. But no entry of /bin/zsh.

The test of which zsh | sudo tee -a /etc/shells would return a good result.

A quick manual edit so /bin/zsh was the only zsh related entry was enough to correct nothing.

After that I did a delete of the /home/usr/.oh-my-zsh directory (I kept my .zshrc file), and did a full reinstall and that removed the chsh problem. Perhaps a combination of some bad oh-my-zsh file and a bad shell file created the error?

David Foerster
  • 36,890
  • 56
  • 97
  • 151
Jaxor
  • 19