Choose your Shell
In most cases today, your "go-to" shell will likely be the bash shell. Of course, you've got the freedom to switch it up if that tickles your fancy, or simply hop into another shell session from where you are now.
Discover the Default Shell
Each user account can be set up to run a particular shell. It's pretty normal for different user accounts to be rocking different shells, all depending on what they need. So, a smart move before diving in is to figure out which shell you're currently using.
The easiest way to determine the current shell is by executing the following command:
echo $SHELLThis will display the contents of the $SHELL environment variable, which will display the shell the current user is running.
What if you want to find out, or enumerate, the shell configuration for other system accounts? You can display the contents of the /etc/passwd file with the cat command:
cat /etc/passwd
We'll revisit the /etc/passwd file a bit later on. But at a quick glance, you might've noticed that at the end of each line there's a bit that tells you which shell each account is set to use.
The cat command (short for concatenate), displays the contents of the file you direct it towards on the terminal. For instance, when we pointed it at /etc/passwd, it promptly laid out its content on our screen. However, if you're specifically interested in a particular account, sifting through the entire file using cat might seem inefficient. There are more precise methods to extract the information you need.
There's a handy way to filter the output of our cat command. Enter stage left: the grep command.
grep is a handy command-line tool that lets you filter for specific patterns or text within files, showing you the lines where they pop up. There are several ways to use grep which we will explore in later sections, but in this example, we will use a feature of the shell known as piping - a posh way of saying "take the output from one command and use it as input for another". We will use cat to print the contents of /etc/passwd to the terminal, "pipe" it (|) into the grep command, and filter the output for a given username:
cat /etc/passwd | grep USERNAMEThe above command will result in output that matches our search term. So, if you wanted to list all of the accounts that are configured to use /bin/noshell, you would enter:
cat /etc/passwd | grep /bin/noshellOpen a New Shell
To try a different shell, simply type the name of that shell. Examples include:
kshtcshcshshdash
There are other shells you can choose from, assuming that they are installed on the system. You can display them with the following command:
cat /etc/shells
You can try a few commands in your shell of choice, then simply type exit when you are finished to return to the previous shell.
Configure a New Default Shell
The following command, if launched as an administrator, or via sudo (more on this later...) will allow you to change the default shell of a specified user:
usermod --shell /bin/sh USERNAMEor
chsh --shell /bin/sh USERNAMEEither of these will set the default shell to be /bin/sh for the user you specify.
Last updated
Was this helpful?