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:

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

    ReplyDelete
  2. 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..

    ReplyDelete
  3. 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

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

    ReplyDelete
  5. AnonymousJune 18, 2010

    Thank you!!! Thank you!!

    ReplyDelete
  6. 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

    ReplyDelete
  7. 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.

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

    ReplyDelete
  9. 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.

    ReplyDelete
  10. 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

    ReplyDelete
  11. In ubuntu, use:

    useradd -Ds /bin/bash

    using

    useradd -D -s /bin/bash

    will set the SHELL default to an empty string.

    ReplyDelete
  12. 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

    ReplyDelete
  13. 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.

    ReplyDelete
  14. 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.

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

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

    ReplyDelete