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
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
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
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
Method 3: Using /etc/passwd File
Open the /etc/passwd file and edit it to your preferred default Linux shell.
$ sudo nano /etc/passwd
Save the file and confirm the changes took place with the following command:
$ grep dnyce /etc/passwd
We have understood the need for changing the default Linux shell and implemented some practical methodologies for achieving the said goals.