When you install Linux Ubuntu, the bash shell is set as the default. But did you know that you can actually use other shells as well?

When creating a new user in Linux, you can specify the default shell that the user will use. The option used for this is the useradd command's -s option. If the user is already created, you can change it using the usermod -s command.

This article summarizes the main shells that can be used with the -s option of useradd, their features, and how to check the list of available shells on your current system.

Developer pondering the useradd -s option with various shell choices


1. Main Shell Types and Features

Shell Path Shell Name Features
/bin/bash Bash The most widely used standard shell. Offers various features such as command editing, autocomplete functionality, and scripting.
/bin/sh Bourne Shell Lightweight and provides minimal functionality. Mainly used in scripting and restricted environments.
/bin/zsh Z Shell (Zsh) An extended version of Bash. Offers excellent autocomplete features and customization options. Recently gaining popularity.
/bin/ksh Korn Shell A shell widely used in commercial environments. Emphasizes speed and efficiency.
/usr/bin/fish Fish Shell A shell recommended for beginners due to its intuitive usage and powerful autocomplete features.
/usr/sbin/nologin or /bin/false Non-login Shell Used for direct login blocking. Frequently used when creating system accounts or service accounts.

2. Checking Available Shells on the Current System

The list of available shells on the current system is stored in the /etc/shells file. You can check it with the following command:

cat /etc/shells

Example output:

/bin/sh
/bin/bash
/usr/bin/bash
/bin/rbash
/usr/bin/rbash
/usr/bin/sh
/bin/dash
/usr/bin/dash

Only the shells listed in this file can be used with the useradd command's -s option.


3. Accurately Checking the Path of the nologin Shell

To verify the exact location of the login-blocking shell (nologin), use the following command:

which nologin

Example output:

/usr/sbin/nologin

Since it may vary between systems, it's advisable to check.


4. Example Use Cases

Adding a User with the Bash Shell

sudo useradd -m -s /bin/bash username

Adding a User with the Zsh Shell

sudo useradd -m -s /bin/zsh username

Adding a System User that Cannot Log In

sudo useradd -r -s /usr/sbin/nologin username

Example command to change an existing user's shell:

sudo usermod -s /usr/sbin/nologin username

Command to check the changed result:

cat /etc/passwd | grep username

Normal output example:

username:x:1004:1004::/home/django:/usr/sbin/nologin

Now that you have a clear understanding of the -s option of useradd and the available shells, manage your accounts safely with the correct shell settings!