43

I want to change my shell from bash to zsh.

I have tried running the following while logged in as user zol:

$ chsh -s /bin/zsh
$ sudo chsh -s /bin/zsh zol
$ su -c 'chsh -s /bin/zsh zol'
# The above all results with:
$ password:
$ chsh: Shell not changed.

# zsh exists in /etc/shells.. 
chsh -l
/bin/sh
/bin/bash
/sbin/nologin
/bin/zsh

What could be wrong? How can I fix it?

6
  • Did you try running 'chsh' without any arguments as zol?
    – George M
    Jun 2, 2012 at 14:48
  • Are you using something like ldap/nis etc.? Jun 2, 2012 at 14:53
  • Much more importantly: Why doesnt it give you more info? That message might be fine for a seasoned sysop but for most people it's downright rude. Im facing the same problem 5 years on, and people wonder why linux has spent the past 20 years not on the desktop.
    – flurbius
    Sep 4, 2017 at 12:26
  • You expected your shell to change instantly? You change your login shell with chsh, which means you will have to log in again.
    – Kusalananda
    Nov 6, 2019 at 17:02
  • No, this is not the reason why Linux has not made it. I actually has taken over the world, most systems on the planet now use a Linux kernel (chances are that your cellphone does), pretty much all webserver, cloudserver etc.. use Linux. But there is a lot of old crap in Linux that needs reform badly. Some of these commands are 30 years old and they are not userfriendly by any measure. Since it is Opensource, it is up TO US to fix this and build something better. Jun 5, 2021 at 1:58

5 Answers 5

36

User account modifications will not be saved if you have opened /etc/passwd (vim /etc/passwd) when you try to change the info.

Alternative: try with usermod (as zol):

$ usermod -s /bin/zsh 

or

$ sudo usermod -s /bin/zsh zol

If this doesn't work either, edit /etc/passwd by hand.

sudo vipw
# set zol's shell to /bin/zsh
:wq
4
  • 9
    please use vipw instead of vim as they set the appropriate file locks. Jun 2, 2012 at 15:06
  • "User account modifications will not be saved if you have opened /etc/passwd" — but why?
    – Thanatos
    Feb 3, 2015 at 19:44
  • It doesn't work too. When I restart Linux virtual machine (centos7), it's OK now!
    – WeizhongTu
    Jul 11, 2016 at 10:56
  • @fromnaboo Can you please explain why you make this claim in your first sentence, as @ Thanatos already asked ? You have not provided any explanation about this, and this seems to spawn out of nowhere, as is.
    – Atralb
    Dec 2, 2020 at 10:07
16

Just ran into this. No matter what I did logging in and back out would not change my shell yet it was listed in /etc/shells and in /etc/passwd.

finally it dawned on me: Maybe I am logged in with another session?

So I did

# who

and it validated I did have indeed other open sessions from other machines:

dom  pts/0        Nov 6 13:53 (10.1.6.121)
dom  pts/1        Nov 5 12:30 (10.1.6.165)
dom  pts/2        Nov 4 12:33 (10.1.6.197)

I then did:

pkill -KILL -u dom

I was immediately logged out and after logging back in: Voila! Shell was changed

1
  • It works, why "logged in with another session" create a problem?
    – Broly LSSJ
    Sep 8, 2022 at 12:39
7

If you see chsh: Shell not changed., it could mean that the shell was already changed.

Check which shell is listed:

cat /etc/passwd | grep `cd; pwd`

If it's correct, log out and back in to have the change take effect.

1
  • Thanks! This was my rookie mistake. I had to log out and log in again for the change to take place.
    – zslim
    Nov 21, 2022 at 21:02
3

When to run "chsh -l" if you to see:

/usr/bin/zsh
/bin/zsh

Then use:

chsh -s /usr/bin/zsh

Warning: The commands was run on Fedora 25, In ubuntun the option "-l" from is out.

4
  • -l is an invalid option for me. I'm on Ubuntu 16.04
    – byxor
    Jul 27, 2017 at 10:39
  • Sorry, I don't give information about the distro where the commands work. In my case I tested on Fedora 25. I try on ubuntu and I verify the option "-l" is out. Jul 27, 2017 at 13:18
  • Regardless, chsh -s worked perfectly. Thanks.
    – byxor
    Jul 27, 2017 at 13:33
  • The option is valid on Manjaro but it still refuses to change the shell.
    – flurbius
    Sep 4, 2017 at 12:28
1

Change it from /etc/passwd

I had some problems with zsh (that is default in manjaro) and I used it for get back to bash.

[infinito@manjaro ~]$ grep infinito /etc/passwd
infinito:x:1000:1000:Sergio N:/home/infinito:/bin/bash      <---here
1
  • 1
    please don't post text as image, you might want to use grep infinito /etc/passwd
    – Archemar
    Apr 20, 2021 at 7:26

This site is temporarily in read-only mode and not accepting new answers.

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