October 19, 2019
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:

[[email protected] ~]$ 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:

[[email protected] ~]$ 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,

[[email protected] ~]$ 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

Vedant Singh

Linux System Administrator | Entrepreneur | Founder Techmion. I have started my career as a Linux system Administrator after that quit my job to start something new that excites me and started a Tech Company in order to provide the best technology to my clients. My Company website link: Technology at its best For Bulk, SMS-Marketing follows the link : https://www.pingsms.in/

View all posts by Vedant Singh →

Leave a Reply

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