370

How is it possible to change the default shell? The env command currently says:

SHELL=/bin/tcsh

and I want to change that to Bash.

Matthias Braun
  • 32,039
  • 22
  • 142
  • 171
mahmood
  • 23,197
  • 49
  • 147
  • 242

3 Answers3

514

Try linux command chsh.

The detailed command is chsh -s /bin/bash. It will prompt you to enter your password. Your default login shell is /bin/bash now. You must log out and log back in to see this change.

The following is quoted from man page:

The chsh command changes the user login shell. This determines the name of the users initial login command. A normal user may only change the login shell for her own account, the superuser may change the login shell for any account

This command will change the default login shell permanently.

Note: If your user account is remote such as on Kerberos authentication (e.g. Enterprise RHEL) then you will not be able to use chsh.

Elijah Lynn
  • 12,272
  • 10
  • 61
  • 91
Summer_More_More_Tea
  • 12,740
  • 12
  • 51
  • 83
  • How to make it permanent? I don't have sudo access – mahmood Oct 24 '12 at 09:26
  • @mahmood It will change the default login shell permanently. – Summer_More_More_Tea Oct 24 '12 at 09:28
  • 11
    `chsh: can only change local entries; use ypchsh instead`. Then ypchsh doesn't have any `-s` option – mahmood Oct 24 '12 at 09:31
  • @mahmood don't know you have a NIS server.:p – Summer_More_More_Tea Oct 24 '12 at 09:34
  • Which setup file does this command changes? I want to undo change done by this command. – Shakti Malik Feb 11 '14 at 11:30
  • 11
    @ShaktiMalik I believe the configure file is `/etc/passwd`, but I didn't double check it. – Summer_More_More_Tea Feb 11 '14 at 13:18
  • 37
    **You must log out and log back in to see this change.** – Neil Traft Jul 06 '14 at 22:03
  • 30
    In my case, I had root access but didn't want to mess with any configurations on the actual host. I added `exec /bin/bash` to `~/.profile` and this allowed me to login directly to bash without making any changes to the server. (The original default shell was just `/bin/sh`) – Niko Aug 18 '14 at 19:38
  • 2
    @BCqrstoO Thank you for this. But what if you type `exit` in bash? Will you logout the server directly or just exit the bash and into the sh and another `exit` required to logout the server? – Summer_More_More_Tea Aug 19 '14 at 04:32
  • 1
    It logs me out of the server entirely and I don't have to enter exit twice, but your mileage my vary. – Niko Aug 19 '14 at 16:09
  • 2
    ~/.profile didn't to it for me. My default was tcsh, so I added exec /bin/bash to my ~/.tcshrc which works quite nicely – narthur157 Apr 24 '15 at 18:01
  • This not worked for me. I use ubuntu 3.19. The command has no effect. I have changed manually the file /etc/passwd – Daniele Licitra Dec 04 '17 at 09:31
  • Just added a note to this answer about it not working for remote users e.g. Kerberos on RHEL, due to enterprise security policies. I am not sure if it is possible to allow it so if someone could clarify that it would be useful. – Elijah Lynn Mar 09 '18 at 18:43
  • 1
    On QNAP QTS running 5.10 kernel , the method of adding "exec /bin/bash" to .profile from Paul Baker works. There is no chsh command on QTS. – tobi delbruck Nov 19 '22 at 06:36
177

You can change the passwd file directly for the particular user or use the below command

chsh -s /usr/local/bin/bash username

Then log out and log in

Desert Ice
  • 4,461
  • 5
  • 31
  • 58
  • 16
    Probably a good idea to try ```which bash``` before invoking the above command; your mileage may vary about location. In my case, it was found in ```/bin/bash``` – Martin Haeberli Aug 17 '16 at 21:16
  • 1
    I can also add that, `chsh` command is part of `util-linux` package; and `chsh -s $(which bash) $USER` should result the same as above. –  May 29 '17 at 01:11
  • There is also `-l` option: "print list of shells". – Betlista Jul 04 '17 at 11:21
  • 6
    it was `chsh -s /bin/bash username` for me – Salvatorelab Nov 29 '17 at 11:42
  • Thank you! This helped me when trying to change it for a different user – Tobias Feil Mar 11 '19 at 11:49
  • This is the necessary alternative [to the top answer] if the user doesn't have a password. Without a username (so setting on self) it asks for a confirmatory password which will always fail. Getting a root/sudo user to set it for you this way is a workaround. – Hashbrown Jul 31 '19 at 02:29
20

You should have a 'skeleton' somewhere in /etc, probably /etc/skeleton, or check the default settings, probably /etc/default or something. Those are scripts that define standard environment variables getting set during a login.

If it is just for your own account: check the (hidden) file ~/.profile and ~/.login. Or generate them, if they don't exist. These are also evaluated by the login process.

arkascha
  • 41,620
  • 7
  • 58
  • 90
  • 8
    Plus 1 for specifically answering the question (THE Default Shell). On Red Hat Linux it is specified in `/etc/default/useradd` – geedoubleya Sep 26 '14 at 08:09
  • @geedoubleya Can you specify what is a difference in default and login shell? – Betlista Jul 04 '17 at 11:25
  • 1
    Hi @Betlista The default shell is the shell that is used for a new users login shell when they are created unless a specific shell is provided as an argument. – geedoubleya Jul 07 '17 at 16:04