×


Change the Default User Shell in Linux OS - Step by step guide ?



Bash shell is commonly used in the Linux system. In most Linux operating systems, the default shell is bash but do you know we can change the default bash shell to any other shell like sh, fish, zsh, csh etc.

Here at LinuxAPT, as part of our Server Management Services, we regularly help our Customers to perform related Linux systems queries.

In this context, we shall look into how to change the default user shell in Linux OS.


How to Find the current shell name ?

To change the default user shell, first of all find the current shell you are using. In the Linux system, the default user shell is bash. There is one file named passwd under the directory /etc that stores essential user account information which is needed during the user log in. 

We can identify the current user shell using that file.

Run the following command to check current user information stored in the file /etc/passwd:

$ grep <current_user> /etc/passwd

For Example:

$ grep linuxapt /etc/passwd

This will display the username and bash of the current shell.

Also, you can use echo command to check the current user shell:

$ echo $SHELL


How to List available shells in Linux ?

To change the user default shell, we need to find out the available shell lists in the Linux system.

Installed shells can be listed by using the following command:

$ cat /etc/shells

Here, you will see that there are  different types of shell such as bash, rbash and dash available in the system.

Before changing the shell, remember the following things:

Root user can be used to change login shell of other users.

If any user account has restricted login shell, then only root user can change the user's shell.

Users will be able to change the shell listed in /etc/shells only.


How to change default sh shell to bash shell ?

In the Linux operating system, there are many ways to change the default login shell. Here, we will explain some commonly used methods.

1. Using chsh utility

If you want to change the default user shell then the chsh utility can be very useful. Run the command chsh with the option -s to change the user shell. It also modifies the /etc/passwd file:

$ chsh -s /bin/sh linuxapt

Where , linuxapt is the username and sh is the shell we are going to change.

$ grep linuxapt /etc/passwd

Here, the default user shell will be changed from bash to sh.

2. Using usermod command

The usermod utility is another way to modify the user account. You just need to specify the option -s or -shell to change the default shell for a user. Remember that you need to have a root privileged account to make the changes:

$ sudo usermod -s /bin/bash linuxapt

Using usermod does not change the user's current shell but sets a default shell to be used in the next login.

$ grep linuxapt /etc/passwd

Here, the default shell of the user will be changed from bash to sh.


How to edit passwd file to change the default User shell in Linux?

In the Linux system, essential user's information is stored in the file /etc/passwd which is needed to login. Default user shell can also be changed by manually editing this file. For this edit the file /etc/passwd using any text editor and change the shell after the username and home directory of a user and save a file:

$ sudo vi /etc/passwd


How to Change the current user shell ?

Changing the current user shell is simple and easy. Just type the shell you want to use in the terminal. But this does not change the default shell for the next login:

$ rbash


[Need help in fixing Linux system issues ? We can help you. ]


Conclusion

This article covers the different ways to change default user shell in Linux OS. In fact it includes instructions for changing the login shell from the command line using chsh, or changing the shell only for a particular terminal application. 


More Linux Tutorials

We create Linux HowTos and Tutorials for Sys Admins. Visit us on IbmiMedia.com

Also for Tech related tips, Visit forum.outsourcepath.com or General Technical tips on www.outsourcepath.com