Wednesday, March 25, 2009

Changing default shell in ubuntu

I faced this problem when I created a new account using command line where the default shell of my new account is /bin/sh. After googling around, I found 2 useful solutions which are listed below:

1. Change user entry in /etc/passwd
a) edit /etc/passwd using any editor

  • $ vi /etc/passwd
b) find the line that belongs to the user (foo) that we about to modify
  • foo:x:1001:1001::/home/foo:/bin/sh
c) change from /bin/sh to /bin/bash
  • foo:x:1001:1001::/home/foo:/bin/bash
d) save
e) Logout and login back

2. Use chsh command
a) type chsh
  • $ chsh
b) You will be asked for password. Enter your password
c) This screen will appear
  • Enter the new value, or press ENTER for the default
    Login Shell [/bin/sh]:
d) Put /bin/bash at the menu and press Enter

Done :)

18 comments:

chfl4gs_ said...

You should use vipw instead of just vi the passwd file.

backhand said...

how about using the options from useradd command

# useradd foo -s /bin/bash

the user foo will be created with the /bin/bash shell allocated to him.. thanks..

Mitch said...

You can change it permanently with the -D option.

# To see current settings
# useradd -D

# To change default shell for all new accounts
# useradd -D -s /bin/bash

Cheers,
Mitch Sheean

William Notowidagdo said...

Thanks for the post. This is just what I need now.

Anonymous said...

Thank you!!! Thank you!!

JP said...

Thanks all. Solution by Mitch Sheean didnt work (tried as root, not error msg, but didnt work).

Had to do manually in /etc/passwd (changed all to bash :D).

cheers
JP

Mitch said...

That's odd that the -D option didn't work for you. What distro do you run?

I use it for new Ubuntu installs. Run it once and it should set your default shell to bash. Any new users you add will show bash in the /etc/passwd file.

Check the man age too for useradd.

Mitch said...

Also, maybe you used the # sign with the command? That should not be part of it. It's meant to denote a prompt.

Josiah said...

You don't need the first bit of the post at all. You can start up bash manually (by issuing `bash' at the prompt), then use `chsh' as stated.

Matty said...

On the question of permanently changing the shell using useradd on Ubuntu, it requires:

useradd -Ds /bin/bash

If you do it with -D -s, it will just change the SHELL default to an empty string.

MMurphy

Matty said...

In ubuntu, use:

useradd -Ds /bin/bash

using

useradd -D -s /bin/bash

will set the SHELL default to an empty string.

Anonymous said...

root@ccc:~#
root@ccc:~# useradd -D -s /bin/bash
root@ccc:~# useradd -D
GROUP=100
HOME=/home
INACTIVE=-1
EXPIRE=
SHELL=/bin/bash
SKEL=/etc/skel
CREATE_MAIL_SPOOL=no
root@:~# ^C

Andrew Mortimer said...

I've included this post on my blog as record for my self and effort to preserve accurate instructions. I have provided a link to this blog citing it as the source of the information. Thank you much.

Andrew Mortimer said...

I've included this post on my blog as record for my self and effort to preserve accurate instructions. I have provided a link to this blog citing it as the source of the information. Thank you much.

lokita jain said...

Thanks you. Its very useful and is
written in simplest way.

lokita jain said...

Thanks, its very useful and is written in simplest way.

Juto Yu said...

Brilliant!

Juto Yu said...

Brilliant!