69

Today I tried to switch to another shell.

First I tried fish, and used chsh -s fish to change fish to default. After some time I found it cannot use ~/.bashrc (&& needs to be replaced by and).

Because I prefer to reusing ~/.bashrc, I found zsh which seems an easier one and followed this documentation to switch to zsh.

While I was running sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)", suddenly it asked me to enter Password:. I entered the root password but got PAM: Authentication failure.

Then I tried chsh -s bash and chsh -s zsh, it always asked me for a password and threw PAM: Authentication failure (not system password). I can't figure this out.

2
  • Check if you have an alias or something with sudo in your .bashrc/.zshrc/.etcrc Mar 1, 2019 at 12:10
  • 1
    This is obviously a bug: I have to enter my password even as root, and the correct password still leads to a permission denied. Sudo must not be invoked when the user is already root. Sep 1, 2021 at 1:52

11 Answers 11

89

Thanks to this question on Server Fault, I worked around this by:

Replacing

auth       required   pam_shells.so

with

auth       sufficient   pam_shells.so

in /etc/pam.d/chsh.

Then it doesn't ask for a password anymore. But I think it better to restore chsh settings after switching the shell.

2
  • 4
    using sed: sudo sed s/required/sufficient/g -i /etc/pam.d/chsh
    – ospider
    Jan 15, 2019 at 2:28
  • Did unfortunately not work. But I commented that line out, changed the shell and removed the comment, again. So your hint was the right one for me. Jun 3, 2019 at 6:26
37

Try this:

sudo chsh -s $(which zsh) $(whoami)
3
  • 4
    this is the way Jul 2, 2021 at 16:49
  • exactly what I was looking for!
    – igops
    Feb 10, 2023 at 9:20
  • "sudo chsh -s /bin/zsh {{ created_user }}" with ansible works like a charm (Thank you) Sep 24, 2023 at 9:52
8
  1. Use which zshto find your zsh location.

    $ which zsh
    /usr/bin/zsh
    
  2. Add /usr/bin/zsh to /etc/shells

  3. Check in /etc/passwd that your config is /usr/bin/zsh

  4. Run chsh -s /usr/bin/zsh

2
  • This only works for the normal user, but not for root. Is it a security feature?
    – Timo
    Jan 4, 2020 at 7:40
  • 2
    could you expand on step 3 please, what if it isn't there?
    – baxx
    Aug 16, 2020 at 12:51
3

An alternate work around –

My /etc/pam.d/chsh file has this section:

# This allows root to change user shell without being
# prompted for a password
auth        sufficient  pam_rootok.so

As the comment suggests, it lets root change the shell without needing to product the password. As such I was able to change my shell (to zsh) by running chsh as root and specifying my user account, eg:

sudo chsh $USER -s $(which zsh)
1
  • For me, comment out this line: # auth required pam_shells.so , then run chsh, then uncomment that line back.
    – Eric
    Jan 31, 2022 at 18:57
1

Try adding at bottom of your $HOME/.bashrc

export SHELL=`which sh`
zsh
exit

This works for me! if you want you can put a welcome text in your shell, but you must install figlet using:

sudo apt install figlet

And overwrite the previous code at bottom of your $HOME/.bashrc

export SHELL=`which zsh`
figlet 'Your welcome message LIKE FOR ME: Welcome'
zsh
exit
1
  • 1
    nice, quick and easy. The first line where you export should be export SHELL=which zsh as in the second block, not which sh
    – melchi
    Aug 5, 2022 at 5:28
1

I had this issue when switching to fish. I accidentally executed chsh -s /usr/local/bin/fish while on my system it should have been chsh -s /usr/bin/fish, but even though the first command warned that the shell did not exist, it still changed it to /usr/local/bin/fish in /etc/passwd. This meant that the second, correct, command failed to authenticate (just like new SSH logins) as the shell did not exist.

The solution for me was to first correct the shell to an existing one in /etc/passwd, and then run the correct chsh command again.

0

For those for whom the top two solutions did not work. I've found my solution here: https://askubuntu.com/a/950531/1168898

There is a workaround for gnome-terminal:

  1. Go to EditProfile preferencesTitle and Command.
  2. Check Run a custom command instead of my shell.
  3. Provide bash as the Custom command (or fish, or anything).
0

This is my solution:

grep -qxF "$(which zsh)" "/etc/shells" || sudo bash -c "echo $(which zsh) >> /etc/shells"
grep -qxF "$(which zsh)" "/etc/shells" && sudo chsh -s "$(which zsh)" "$(whoami)"
  1. Check whether /etc/shells contains the zsh executable you want. If it doesn't, append it to the file.
  2. If /etc/shells contains the shell you want, change your user's shell to that.

I have some parts abstracted into variables but for simplicity's sake, I included the full logic as plainly as possible.

0

i had the same problem when i try to change my shell, what i did is go to your /etc/shells , find your user and than change the /bin/bash for what you want.

0

If you use SCP/SFTP/rysnc, be very cautious when making changes to your shell startup. These tools will FAIL in a very difficult to troubleshoot way if anything is printed at login. Better yet, just use the chsh solution and do it the right way.

To work around this, make sure that your non-interactive shell login will be silent by wrapping your ZSH customizations inside a check for interactive. For example, based on the above answer by @Alpha for Bash, this is the modified .bashrc to support both remote file transfers and ZSH for interactive logins:

if [[ $- == *i* ]]
then
  export SHELL=`which sh`
  zsh
fi
0

I used /bin/fish after entering in root user with sudo su
After reading @Mithril that mentions /etc/pam.d/chsh file with the following comment:

# 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

I notice that adding /bin/fish to /etc/shells was enough to let me change back.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .