How to - Change the default shell of a user using chsh

You must have noticed that every time you open a terminal or login on a text console, you get a bash shell. And we don’t remember where was this option asked during the installation, right? The option for a shell is actually one of the user properties just like a user’s home directory, password, full name etc. Using chsh command we can change our default shell.

You may be wondering where is this information stored anyway. You can find this info in the /etc/passwd file. The file is readable by everyone. The final attribute in every line is the default shell. As you can see this is /bin/bash in my case.

sahni:x:1000:1000:sahni,,,:/home/sahni:/bin/bash

Lets get to the main part now. Using chsh command, a regular user can change his default shell. If you are a superuser i.e. root, you can change this shell for everyone.

[shredder12]$ chsh -s /bin/sh #for a regular user

[root]# chsh -s /bin/sh user_name #for root

Basically, since a regular user can’t edit the /etc/passwd file, chsh does this for you. Now, the key question - does this mean I can use any shell? Not really. For security reasons, you are only allowed to enter the shells that are mentioned in the file /etc/shells and please do mention the exact full path as it is mentioned in this file.

[shredder12]$ cat /etc/shells

# /etc/shells: valid login shells
/bin/csh
/bin/sh
/usr/bin/es
/usr/bin/ksh
/bin/ksh
/usr/bin/rc
/usr/bin/tcsh
/bin/tcsh
/usr/bin/esh
/bin/dash
/bin/bash
/bin/rbash
/usr/bin/screen

Please note that, this restriction is applicable only to the chsh command. The root user can still directly edit the /etc/passwd file to change the default shell regardless of whether the shellname or path exists in /etc/shell or not.

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <img> <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockquote> <h1> <h2> <h3> <h4> <h5> <h6> <p> <br>
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Image links with 'rel="lightbox"' in the <a> tag will appear in a Lightbox when clicked on.

More information about formatting options

Type the characters you see in this picture. (verify using audio)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.