Skip to content
Related Articles

Related Articles

Improve Article

How To Change Default Shell In Linux

  • Last Updated : 21 Jul, 2021

In most Linux systems, the default shell is bash but we can change that to any other shell-like zsh, fish, sh, and any other. In this article, we are going to show how to change that default shell to any other shell in Linux systems. To change the user’s shell, first, let’s find the current shell. There are many ways by which we can change the shell of any user on a Linux system. We are going to see three methods of changing the user’s shell.

Find your current shell name

In Linux systems, there is one file which is /etc/passwd. The /etc/passwd file stores essential information of user accounts, which is required during login. By using this file we can identify the current user login shell.

We are going to see the current user information in the /etc/file using the following command:

grep `whoami` /etc/passwd

In the above image we can see that the user nishant (current user) has home directory /home/nishant and the shell is /bin/sh

List your shells in Linux

Now to change the shell, first, we need to see which shells are installed on the system. We can check installed shells using the following command :

cat /etc/shells

This will show all shells as follows:

Before moving further, first understand who can change the user shell

  • Users can change shell to any other shell listed in /etc/shells/.
  • The root account can be used to change any other user login shell.
  • If an account has a restricted login shell, then only the root can change that user’s shell.

Changing default sh shell to bash

Using usermod command

usermod is a command that modifies the system account files. usemod can change the shell of Users by modifying file /etc/passwd. usermod command provides the -s or –shell option to change the user’s login shell.

In this example, we are going to change the shell of a user named nishant. We are going to change the shell from /bin/sh to /bin/bash of user nishant using usermod command.

sudo usermod --shell /bin/bash nishant

With usermod command mention shell and usernmae after –shell option.

Now you can see the shell use changed. In the above commands, replace nishant with the user name whose shell has to change.

Using chsh Utility

chsh is the utility to change a user’s login shell. chsh provides the -s option to change the user’s shell. This method also modifies the file /etc/passwd. Use the following command to change shells using chsh:

chsh -s /bin/bash nishant

Change User Shell to /etc/passwd File

 As we see in the above two methods, the usermod command and chsh utility modify the /etc/passwd file and change the user shell. We can do that manually also by editing the /etc/passwd file. Just change the shell after the username and home directory in the /etc/passwd file and save the file.

nano /etc/passwd

My Personal Notes arrow_drop_up
Recommended Articles
Page :