June 13, 2024
change your default ssh

How to change default shell in Linux

What is a SHELL?

The shell executes a program in response to its prompt. When you give a command, the shell searches for the program, and then executes it. For example, when you give the command ls, the shell searches for the utility/program named ls, and then runs it in the shell. The arguments and the options that you provide with the utilities can impact the result that you get. The shell is also known as a CLI, or command-line interface.

Changing default shell

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

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

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.
 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

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

Vedant Kumar

Currently I'm working as an Implementation Engineer, Started my career as an System Administrator - Linux. Additionally loves to explore new technologies and research about new open-source software that ease the development cycle.

View all posts by Vedant Kumar →

Leave a Reply

Your email address will not be published. Required fields are marked *

The reCAPTCHA verification period has expired. Please reload the page.


Ad Blocker Detected!

We've noticed that you are using an ad blocker. Advertising helps fund our server cost and keep it truly independent. It helps to build our content creator team. So please disable your ad blocker, and help us to keep providing you with free- great content - for free. Thank you for your support.