In this Linux quick tip we will discuss changing your current and default shells. 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 shell to any that you desire.
How to Find Which Shell I am Currently Using
When you first log into a system, you might want to check which shell you are currently using. The most efficient way to find your currently running shell is to use the ps
command with a few options.
[savona@putor ~]$ ps -p $$
PID TTY TIME CMD
29439 pts/1 00:00:00 bash
In the above example we used the -p
or --pid
option followed by $$
. The double dollar signs pass the process ID of your shell to the ps
command which in turns outputs the desired information.
Alternatively, you can use the echo
command to display the name of your shell like so:
[savona@putor ~]$ echo $0
bash
How to Find My Default Shell
The above commands show you which shell you are currently using. However, the current shell isn't necessarily your default shell.
There are several ways to find your default shell. In my opinion, the easiest method is to echo the SHELL variable.
[savona@putor ~]$ echo $SHELL
/bin/bash
This will print the users default shell to standard output.
You can also use grep to search your username in /etc/passwd
to see which shell is configured as your default shell.
[savona@putor ~]$ grep savona /etc/passwd
savona:x:1000:1000:savona:/home/savona:/bin/bash
List All Available Shells on Your Linux System
Next, you will need to know which shells are available to you on the 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 simply 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 now 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 is 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 is 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/sh
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.
Resource and Links
Join Our Newsletter
Categories
- Bash Scripting (17)
- Basic Commands (50)
- Featured (7)
- Just for Fun (5)
- Linux Quick Tips (98)
- Linux Tutorials (65)
- Miscellaneous (15)
- Network Tools (6)
- Reviews (2)
- Security (32)