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