How To Change Default Shell In Linux
Last Updated :
26 Dec, 2024
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
1. 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 username 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.

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

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

The three methods mentioned above provide simple and effective ways to change the default shell in Linux.
Conclusion
Changing the default shell in Linux is a straightforward process with multiple methods to suit different preferences. Whether using the usermod
command, the chsh
utility, or manually editing the /etc/passwd
file, these techniques provide flexibility for managing user environments.
By identifying the current shell, checking available options in /etc/shells
, and ensuring proper permissions, users can easily switch to popular shells like zsh
, fish
, or any other supported option.
Similar Reads
How to change the default SSH port in Linux SSH (Secure Shell) is a network protocol used to securely connect to the remote server where the data between the server and client is transferred in an encrypted format. In the world of Linux system administration and security, one essential practice is changing the default SSH port. This article w
7 min read
How to Run a File in Linux The command line is one of the most powerful tools in Linux. It allows you to execute commands, manage files, and automate tasks all from a single terminal window. One common task you'll often need to do is run a file, whether itâs a script, a compiled program, or even a text file. In this article,
6 min read
How to Run a Shell Script in Linux Shell scripts are a powerful way to automate tasks and manage system processes in Linux. These scripts, written in shell programming languages like Bash, allow users to execute a sequence of commands efficiently. In this guide, we'll show the steps to check a shell script in Linux before running it,
4 min read
How to Change Default Display Manager in Ubuntu In Linux desktop systems, the display manager is a crucial component that handles user authentication and manages user sessions. The display manager is responsible for presenting the login screen and loading the desktop environment after successful authentication. Some popular display managers inclu
4 min read
How to Change the Output Color of Echo in Linux When working with a computer, some users may encounter a situation where they need to output text in a different color. The colors we are familiar with by now will have been worked out for our particular machine and thus can be replaced easily if needed. Echo is a Linux command that can be used to c
9 min read
How to Rename a Group in Linux? Renaming a group in a Linux system is a straightforward but essential administrative task. If you're reorganizing your user management structure or enhancing security measures, this quick guide will walk you through the simple steps to rename a group. Linux provides a powerful command, 'groupmod' to
4 min read
How to Delete User in Linux | userdel Command Managing user accounts is an essential aspect of Linux system administration. Understanding how to delete a user in Linux is crucial, whether you need to remove an unused account, revoke access for a departing employee, or clean up your system for security reasons. Here, we will explore the 'userdel
5 min read
How to Change The Primary Group of a User in Linux? In the field of Linux system administration, learning the modification of the primary group is essential. In this article, we are going to deliver concise details about user groups and how to manage them. What is a Primary Group?In Linux, every user is associated with a primary group. The primary gr
7 min read
Kali Linux - Terminal and Shell Generally, operating systems have 2 interfaces GUI(Graphical User Interface) and CLI(Command Line Interface) and the same is the case with Linux Based Operating Systems. Linux Operating Systems are generally packed with terminal emulator packages for CLI based functioning and Desktop environment pac
3 min read
Setting python3 as Default in Linux Python 2 support ended on 1-January-2020, and many major projects already signed the Python 3 Statement that declares that they will remove Python 2 support. However many of us prefer to code on python interpreter for tiny code snippets, instead of making .py files. And when we fire command 'python'
1 min read