48

I was surprised that I didn't find this question already on the site. So, today $ came up after I logged in as a new user. This was unexpected because my main user's prompt starts with username@computername:~$.

So, how do I switch from this other shell to bash?

mouche
  • 1,315
  • 2
  • 16
  • 15

3 Answers3

71

Assuming the unknown shell supports running an absolute command, you could try: /bin/bash

To change the default shell, I would use chsh(1). Sample usage: chsh -s /bin/bash $USER

Pat Myron
  • 103
Kevin M
  • 1,973
  • 1
    Does chsh permanently change the shell or just for the current session? – mouche Aug 30 '10 at 02:35
  • 10
    @mouche Permanently; it changes your entry in /etc/passwd – Michael Mrozek Aug 30 '10 at 02:36
  • @mouche, chsh(1) will only allow to change to a shell that is listed in /etc/shells (and is available, presumably). chsh -l lists the alternatives. Be careful, some (like nologin) are defined for accounts that should never be used to login (nice way to lock yourself out), there might be local additions for special uses. – vonbrand Feb 29 '16 at 15:56
20

You type in bash. If you want this to be a permanent change the default shell to /bin/bash by editing /etc/passwd.

Here's some snippets from my /etc/passwd:

avahi:x:84:84:Avahi daemon:/:/bin/false
xenoterracide:x:1000:100::/home/xenoterracide:/bin/zsh
postgres:x:88:88::/var/lib/postgres:/bin/zsh
bob:x:1001:1001::/home/bob:/bin/bash
usbmux:x:140:140:usbmux user:/:/sbin/nologin

The very last field contains the shell, Modifying the field after the last : to a valid or invalid shell will work. /bin/false and /sbin/nologin both mean the user doesn't have a real login shell, although if pam is not set up right this doesn't mean they can't login (I reported a bug on this in Arch Linux, because you can login graphically without having a login shell). /bin/bash and /bin/zsh are both valid shells, see /etc/shells for a list of valid shells on your systems. Here's my /etc/shells if you're interested.

/bin/sh
/bin/bash
/bin/ksh
/bin/zsh
/bin/dash

Yes you can use chsh or usermod to do the same things, please remember these are just structured text files, and TIMTOWTDI.

tshepang
  • 65,642
xenoterracide
  • 59,188
  • 74
  • 187
  • 252
  • 11
    You probably want to use chsh instead of manually editing passwd – Michael Mrozek Aug 30 '10 at 02:38
  • @Michael there are about 5 (POOMA) different ways to change the shell in /etc/passwd I didn't feel like listing any of them, because I always do it manually. chsh and usermod can both do it. – xenoterracide Aug 30 '10 at 12:27
  • Messing around with configuration files is a Bad Idea(TM), an error might make the system unusable. Yes, it is often the only/fastest way, but then do it with *extreme care*. – vonbrand Feb 29 '16 at 15:58
16

If chsh or manually editing the config won't work, but a ~/.profile script is executed at login, add this line:

exec /bin/bash --login
Kevin Cantu
  • 3,794