16

I learned a new command, at least I thought, because this command : chsh, does not behave like described.

It was described to work like this:

  1. cat /etc/shells to know, which shells are installed,so you can choose among them.
  2. do echo $SHELL to know, which shell you are using.
  3. choose one of the shells and type chsh -s /path/to/shell
  4. enter password and verify with echo $SHELL, that you are in a new shell.

I have done this and I got no error message when entering the password, but I was still in the same shell.

% echo $SHELL
/bin/bash
% cat /etc/shells
# /etc/shells: valid login shells
/bin/sh
/bin/dash
/bin/bash
/bin/rbash
% chsh -s /bin/sh
Password: 
% echo $SHELL
/bin/bash
4
  • 5
    You have to logout and login again first. May 3, 2017 at 18:58
  • 1
    text should be posted as text
    – phuclv
    May 4, 2017 at 4:02
  • I edited my post, deleted the image and pasted the text instead, but the image came back over night.
    – sharkant
    May 4, 2017 at 7:58
  • @sharkant It looks like someone had an edit in a review queue and it got approved, which edited your post after the fact. I thought the SE edit system wouldn't overwrite a new edit with an old one, but heh, who knows?
    – Zan Lynx
    May 5, 2017 at 4:58

2 Answers 2

20

Log out and log in again.

The chsh command will update the /etc/passwd file, but it does not change the current shell nor the value of the $SHELL variable in the current shell (it has no way of doing that). This is the reason you need to log in again; you have to start a new login session for a change to take effect.

4
  • I do not understand what a login shell is and how I know if I am in a login shell or some kind of not login shell. How do I start a new login session?
    – sharkant
    May 3, 2017 at 19:28
  • 1
    @sharkant The point is that the information that you changed in the /etc/passwd is not read until you log in next time. You will have to log out completely, and log in again for the change to take effect. If you fail in doing this, then rebooting the machine will also work.
    – Kusalananda
    May 3, 2017 at 19:38
  • 1
    I think I understand you this time: so the chsh -s /path/to/shell command does not change immediately the shell i am in, but it changes an entry inside /etc/passwd which will take effect when I start the shell?
    – sharkant
    May 3, 2017 at 19:46
  • @sharkant That's exactly the way it works! I'm happy I finally understood you misconception. I will update the answer.
    – Kusalananda
    May 3, 2017 at 19:48
7

Using usermod utility command worked in my case. Running on the ubuntu 18.04.

  1. First, check current value

grep nameofuser /etc/passwd

  1. change it

sudo usermod --shell /bin/bash nameofuser

  1. Verify it

grep nameofuser /etc/passwd

1
  • 1
    Thaaaaaaaank you
    – Peter
    Jun 2, 2020 at 6:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.