In this Linux quick tip we will discuss changing a users (or your own) shell. There was once a time when bash was the default shell on almost all Linux systems. That is not necessarily true anymore. However, after this short tutorial you will feel comfortable changing your default shell to any that you desire.

How to Check Which Shell You Are Using

When you first log into a system, you might want to check which shell you are currently using. There are several ways to find your current shell. In my opinion, the easiest method is to echo the SHELL variable.

[savona@putor ~]$ echo $SHELL
/bin/bash

This will print the currently used shell to standard output.

List All Available Shells on Your Linux System

Next, you will need to know which shells are available to you on current system. Thankfully, most Linux systems keep a list of installed shells handy. Simply cat the /etc/shells file to see a list of installed shells.

[savona@putor ~]$ cat /etc/shells 
/bin/sh
/bin/bash
/usr/bin/sh
/usr/bin/bash
/usr/bin/tmux
/bin/tmux

As a user, you can change your shell to anything listed in this file. You will need to have root privileges to use a shell not listed in this file. You will also need root (or sudo) privileges if you want to change your shell from a restricted shell (rbash, rksh, etc.).

Changing Your Shell in Linux

Now that you know how to check your current shell and which shells are available, let’s discuss changing your shell.

You can change the shell you are currently using. By changing the current shell you can instantly use the shell of your choice. However, the next time you log in you will be dropped back to your default shell. In the following sections we will show you how to change both your current and default shells.

Change Your Current Shell

To change your current shell simple run the shell you want to use on the command line. For example to use the Z Shell:

[savona@putor ~]$ zsh
[savona@putor]~% 

As you can see the prompt changes and we are not in Z Shell. Remember, this does not change your default shell. Your default shell will still be loaded the next time you log in.

Using usermod to Change Your Default Shell

The usermod utility it used to modify user accounts. Using the -s or --shell option allows you to easily change the default shell for a specified user. Root (or sudo) access in necessary for using the usermod command.

# Show current shell
[savona@putor ~]$ echo $SHELL
/bin/bash

# Show default shell
[savona@putor ~]$ grep savona /etc/passwd
savona:x:1000:1000:savona:/home/savona:/bin/bash

# Change default shell
[savona@putor ~]$ sudo usermod -s /bin/sh savona

# Show current shell
[savona@putor ~]$ echo $SHELL
/bin/bash

# Show default shell
[savona@putor ~]$ grep savona /etc/passwd
savona:x:1000:1000:savona:/home/savona:/bin/s

NOTE: Using usermod does not change your current shell, it simply sets the default shell to be used the next time you log on.

Changing Your Shell Using the chsh Command

If you do not have root/sudo access you can still change your default shell. Usually, the chsh utility does not require you to have a privileged account. The syntax is very similar to the usermod command, simply pass the -s option followed by the desired shell.

[savona@putor ~]$ chsh --shell /bin/sh
Changing shell for savona.
Password: 
Shell changed.

There you have it. You should now be comfortable with finding your current shell, your default shell, and changing your shell.