How to change Default Shell in Linux

Here in this post I will explain about how to change the default bash shell login to other available shells in linux.

To change the shell login, the command used is chsh. To check the available shells type the following command in terminal.

cat /etc/shells

For example, If you like to have python prompt as your default shell login, then add python to the shells file under /etc.

To add : Open a Terminal, Copy and paste the following command in the Terminal. Type the password for the user, when prompted. You need to have root access to do this.

sudo vim /etc/shells

The above command will open the shells file in vim editor, you can use your favourite editor to edit this file. Add this line “/usr/bin/python” to end of the file. Save it and exit.

Now use chsh command to change the shell login to python prompt. To change type the following command in the terminal and type the password for the user, when prompted.

chsh -s /usr/bin/python

Now restart your system and open a terminal you will find the magic. Python prompt will be your default shell login now.

Using python prompt you can change back to default bash shell login.

Open a terminal thats your python prompt and do the steps as follows.

>>> import os
>>> os.system(“chsh -s /bin/bash”)

Once you finish type the above code in python prompt. Type the password for the user and enter, then restart your system. Thats it.

If you have changed to other shell like sh or something then use the same command to change back the shell login.

chsh -s /bin/bash

Hope this will be helpful for you!!!