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,077
  • 4
  • 18
  • 25

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
  • 289,791
  • 117
  • 680
  • 835
  • Yes, I have seen that message also, but thought it was related to the same issue, that is the default shell will not change. The most trying part of the whole issue is that I CAN start a zsh session from bash but still cannot change the default shell. – RCF Jun 08 '14 at 12:31
  • @Oli--OK, I have appended the line to /etc/shells. No change, same error messages. – RCF Jun 08 '14 at 13:32
  • After looking at the contents of the /etc/shells file there were two entries. The original one created using tee and the second using your code also tee. The first entry in the file contained an extra space. Seems that Ubuntu did not like the extra space and ignored the second entry. – RCF Jun 09 '14 at 01:18
  • It appears that one has to restart the server or the current shell to get PAM to update. There is probably a pam service that can be restarted to get the updated list of shells. – scarver2 Nov 25 '14 at 18:27
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
  • 35,754
  • 55
  • 92
  • 145
Jaxor
  • 19
  • 3