Most modern distributions will come with BASH (Bourne Again SHell) pre-installed and configured as a default shell.
The command (actually an executable binary, an ELF) that is responsible for changing shells in Linux is chsh
(change shell).
We can first check which shells are already installed and configured on our machine by using the chsh -l
command, which will output a result similar to this:
[user@localhost ~]$ chsh -l
/bin/sh
/bin/bash
/sbin/nologin
/usr/bin/sh
/usr/bin/bash
/usr/sbin/nologin
/usr/bin/fish
In some Linux distributions, chsh -l
is invalid. In this case, the list of all available shells can be found at /etc/shells file. You can show the file contents with cat
:
[user@localhost ~]$ cat /etc/shells
# /etc/shells: valid login shells
/bin/sh
/bin/bash
/sbin/nologin
/usr/bin/sh
/usr/bin/bash
/usr/sbin/nologin
/usr/bin/fish
Now we can choose our new default shell, e.g. fish
, and configure it by using chsh -s
,
[user@localhost ~]$ chsh -s /usr/bin/fish
Changing shell for user.
Password:
Shell changed.
Now all that is left to do is preform a logoff-logon cycle, and enjoy our new default shell.
If you wish to change the default shell for a different user, and you have administrative privileges on the machine, you'll be able to accomplish this by using chsh
as root
. So assuming we want to change user_2
's default shell to fish, we will use the same command as before, but with the addition of the other user's username, chsh -s /usr/bin/fish user_2
.
In order to check what the current default shell is, we can view the $SHELL
environment variable, which points to the path to our default shell, so after our change, we would expect to get a result similar to this,
~ echo $SHELL
/usr/bin/fish
chsh
options:-s shell
Sets shell as the login shell.
-l
, --list-shells
Print the list of shells listed in /etc/shells and exit.
-h
, --help
Print a usage message and exit.
-v
, --version
Print version information and exit.