Home Linux Commandline Tips How to Change the Default Shell in Linux System

How to Change the Default Shell in Linux System

Under the Linux operating system environment, a shell can be described as a program that takes user inputs from the computer keyboard in form of commands and interprets them with the aim of yielding immediate execution results or leading to another program execution instance.

As you familiarize yourself with Linux, you will get the opportunity to meet and interact with many Linux-oriented shell environments like bash, ksh, fish, sh, and zsh. Due to the popularity of Bash Shell, there is a high chance that you are using it now as the default shell on your Linux system.

Why Change Default Shell in Linux?

Opting to change the default Linux shell makes sense due to the following reasons:

  • A Linux shell-like nologin shell easily disables/blocks normal user login hence a key aspect of Linux’s user management.
  • A shell wrapper program/script makes it possible to delay the execution of user commands until that user logs them. In this case, the user login shell is specific to the shell wrapper.
  • On a shared network, you meet specific user demands like the ones associated with administrative rights when you change Linux’s default shell.

Listing Valid Login Shells in Linux System

Before you consider changing the default shell in your Linux system, first list the valid login shells that are at your Linux OS disposal:

$ cat /etc/shells
List Default Linux Login Shells
List Default Linux Login Shells

Before we proceed and demonstrate how we can switch from one Linux shell to another, take note of the following:

  • Only listed shells in the /etc/shells file can be switched to by normal and logged-in Linux users.
  • Shells not listed in the /etc/shells file can only be run/executed by a root/sudoer user.
  • Linux OS accounts with restricted login shells can only be changed once you sign in as a root/sudoer user.

Ways of Changing the Default Linux Shell

We will be looking at the following approaches to change the default shell in Linux.

Method 1: Using the usermod Utility

The primary use of the usermod utility is solely for the modification of the Linux user account details stored in the /etc/passwd file. Using the usermod command together with the -s or --shell command option makes it possible to change the default Linux shell.

The following command checks the account information such as default shell for user dnyce.

$ grep dnyce /etc/passwd 
Check User Linux Shell
Check User Linux Shell

As you can see, the dnyce user is using bash as the default Linux shell. To change from /bin/bash to /bin/dash, execute the following command:

$ sudo usermod --shell /bin/dash dnyce  
Change User Linux Shell
Change User Linux Shell

Method 2: Using the chsh Utility

The chsh utility command also uses the -s or --shell options while changing the default Linux shell.

Let us change the current shell from /bin/dash to /bin/rbash.

$ sudo chsh --shell /bin/rbash dnyce
Change User Shell in Linux
Change User Shell in Linux

Method 3: Using /etc/passwd File

Open the /etc/passwd file and edit it to your preferred default Linux shell.

$ sudo nano /etc/passwd 
Change Linux User Shell
Change Linux User Shell

Save the file and confirm the changes took place with the following command:

$ grep dnyce /etc/passwd
Check Linux User Shell
Check Linux User Shell

We have understood the need for changing the default Linux shell and implemented some practical methodologies for achieving the said goals.

Ravi Saive
I am an Experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies. Founder of TecMint.com, LinuxShellTips.com, and Fossmint.com. Over 150+ million people visited my websites.

Each tutorial at UbuntuMint is created by a team of experienced writers so that it meets our high-quality standards.

Was this article helpful? Please add a comment to show your appreciation and support.

Got something to say? Join the discussion.

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published or shared. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.