How do I make Bash my default shell on Ubuntu?

107

25

I have a .bash_profile in my home directory, but it isn't getting run on login. If I do the following, then things seem to be as I expect:

ssh myhost
bash
source ~/.bash_profile

But normally that all happens on login. Thoughts?

James A. Rosen

Posted 2009-09-25T12:03:09.683

Reputation: 1 762

3Also make sure that you don't have a ~/.profile or ~/.bash_login, as only one of the three is sourced. (I forgot the exact order.) – user1686 – 2009-09-25T15:20:06.923

3Why do you have a different question in the title and different one in the body of your post? – pabouk – 2013-11-09T10:25:16.057

Answers

176

Use:

chsh

Enter your password and state the path to the shell you want to use.

For Bash that would be /bin/bash. For Zsh that would be /usr/bin/zsh.

akira

Posted 2009-09-25T12:03:09.683

Reputation: 52 754

9You must log out and log back in to see this change. – Neil Traft – 2014-07-06T21:59:17.133

1you rock dude! thx – Waqas – 2014-11-26T14:50:07.813

@kdgregory I found on one particular server that chsh and sudo chsh both resulted in chsh: PAM: Authentication failure - no idea why. In my case, editing /etc/passwd worked however. – drevicko – 2018-11-21T07:45:50.907

1And on ubuntu the path to the shell you want to use is... /bin/bash (and /bin/sh is not the same) – Harry Wood – 2012-03-02T01:01:23.657

15+1 - not sure why the OP decided that editing the password file was a better choice, but this is the best answer – kdgregory – 2009-09-25T12:51:26.580

1Yeah beat me to it, this is the standard way. – John T – 2009-09-25T13:49:05.377

1You saved my day!! – Surya – 2013-12-24T13:41:49.743

49Or you can use sudo chsh -s /bin/bash username – Oleg Vaskevich – 2014-01-21T04:03:04.830

37

On top of akira's answer, you can also edit your /etc/passwd file to specify your default shell.

You will find a line like this example:

john:x:1000:1000:john,,,:/home/john:/bin/sh

The shell is specified at the end.

John T

Posted 2009-09-25T12:03:09.683

Reputation: 149 037

3You must log out and log back in to see this change. – Neil Traft – 2014-07-06T22:01:34.360

2If you're running a server without user passwords - providing access only through public/private ssh keys ... it also makes a lot of sense. chsh requires a password. – Keith John Hutchison – 2015-09-10T02:42:19.867

For whatever reason sudo chsh did not work on Ubuntu for me, and I still logging in without a shell. This worked for me, though. – Nate Glenn – 2016-12-21T09:09:46.097

:/bin/sh or :/bin/bash – Vivek – 2018-04-27T07:15:35.970

8Better to use the 'chsh' command as suggested by akira -- less chance to screw something up by mistake. – Lars Haugseth – 2009-09-25T13:17:27.223

5not to mention 'chsh' is available when you can't write to /etc/passwd – quack quixote – 2009-10-07T11:30:02.890

1But if you so have access to modifying the /etc/passwd and you're careful, John's answer is making good use of the tools the system provides. – AJP – 2014-04-26T11:00:21.053

4

Enable bash:

$ /bin/bash

Change shell for user:

$ sudo usermod -s /bin/bash username

where:

  -s, --shell SHELL             new login shell for the user account

Vitaly

Posted 2009-09-25T12:03:09.683

Reputation: 141

2(1) What do you mean by “enable bash”? (2) The user wants to change his own login shell on a remote system.  Why do you assume that he has sudo access on that system?  Why do you provide instructions in terms of changing another user’s login shell? – G-Man Says 'Reinstate Monica' – 2018-01-26T03:24:37.900

Using chsh (as suggested above) did not work for me. This command did! – Per Lindberg – 2019-02-12T09:30:33.587

4

You might check your terminal program. It might be configured to run /bin/sh rather than /bin/bash

Bash executes .bash_profile only for login sessions. .bashrc is executed for all bash sessions, not only login sessions. Try sourcing .bash_profile from .bashrc (avoid circular dependency!) or configuring your terminal program to run /bin/bash -l as a shell program.

Tadeusz A. Kadłubowski

Posted 2009-09-25T12:03:09.683

Reputation: 2 005

2terminal program has nothing to do with the problem because it is the sshd on the remote machine, which spawns the new shell. – akira – 2009-09-26T04:31:50.873

2

One alternative is to rename your startup script into .profile. This file is being source by most Unix shells.

mathk

Posted 2009-09-25T12:03:09.683

Reputation: 141

1

To make any shell your default, first verify it is installed and recognized on your computer by looking at the contents of /etc/shells:

$ cat /etc/shells
# /etc/shells: valid login shells
/bin/sh
/bin/bash
/usr/bin/bash
/bin/rbash
/usr/bin/rbash
/bin/dash
/usr/bin/dash
/usr/bin/fish

Then use chsh to change your shell:

$ sudo chsh -s /usr/bin/bash $(whoami) # or sudo chsh -s /bin/bash $(whoami)

References

  1. https://linux.die.net/man/1/cat
  2. https://linux.die.net/man/1/whoami
  3. https://linux.die.net/man/5/shells
  4. https://linux.die.net/man/1/chsh

Behrang Saeedzadeh

Posted 2009-09-25T12:03:09.683

Reputation: 1 834

1

If you somehow don't see your username in the /etc/passwd file [this is the case when your system is under control of some other domain e.g. in IT companies] Or it says "user not found" with chsh option than below process might help you.

The logic behind the below trick -> On Ubuntu, /bin/sh is dash. You can switch your system to using bash. On Ubuntu, /bin/sh is a symbolic link to dash. You can make it a symbolic link to bash instead.To change it, run

sudo dpkg-reconfigure dash

And press No to switch to bash.

Now, go to Terminal->Edit->preferences->Command and tick the checkbox with statement

Run command as login shell

And that's it.

saurabh gupta

Posted 2009-09-25T12:03:09.683

Reputation: 11

0

There's not enough information in your question for me to say for sure, but I've hit the same problem before. Assuming you've already get /bin/bash set in your password entry, it may be the way your terminal launches.

If you're trying to launch a GUI terminal, say gnome-terminal you may be expecting the shell to read your bash startup files. However, this doesn't happen on Ubuntu and maybe other systems by default.

The way I've fixed it on Ubuntu is to edit the gnome-terminal preferences, and set the startup command to be bash -l. -l is short for --login. This tells bash to startup as as login shell, which causes it to load the startup scripts as you get when logging in via ssh.

I'm sure there's a good rationale for this being the way it is, but I found it surprising and a more than a bit annoying as I share the same profiles across linux, cywgin and macos systems.

edk750

Posted 2009-09-25T12:03:09.683

Reputation: 101