HB Computer Security | Aide Memoire
  • Introduction
  • Core Technical Skills
    • Core Skills
      • Linux
        • Getting to Know Linux
          • Using the Shell
            • Shells, Terminals, and Virtual Consoles
            • Choose your Shell
            • Shell Commands
              • Non-PATH Commands
              • Command History
                • Command Line Editing
                  • Keystrokes for Navigating Command Lines
                  • Keystrokes for Editing Command Lines
                  • Keystrokes for Cutting and Pasting Text from within Command Lines
                • Command Line Recall
                  • Keystrokes for Command Line Recall
              • Connecting and Expanding Commands
                • Piping Between Commands
                • Sequential Commands
                • Expanding Commands
            • Shell Variables
              • Common Shell Variables
            • Aliases
            • Create your Own Shell Environment
              • Modification Ideas
          • Navigating the Linux File System (LFS)
            • Filesystem Commands
            • Listing Files and Directories
            • File Permissions and Ownership
              • Modifying Permissions with chmod
              • Modifying Default Permissions with umask
              • Change File Ownership with chown
            • Copying, Moving, and Removing Files
            • Finding Files
              • locate
              • find
              • grep
            • Downloading Files
              • axel
              • wget
              • curl
                • User-Agent: Googlebot
          • Working with Text Files
            • Using vim and vi to Edit Text Files
              • Starting with vi
              • Adding Text
              • Moving Around in the Text
            • Text Manipulation
        • System Administration
          • Installing Linux
            • Installing from Live Media
            • Installing in the Enterprise
            • Partitioning Hard Disks
              • Tips for Creating Partitions
          • Account Administration
            • The root Account
              • Becoming root with su
              • sudo
                • The /etc/sudoers File
                • Granting sudo privileges
                  • visudo Guidance
                • Useful sudo Hints
            • Other Administrative Accounts
            • Standard User Accounts
              • Risks of userdel: Orphaned Files
          • Graphical Remote Administration
            • Cockpit
              • Installation Guide
            • Remote Desktop Protocol with xrdp
              • Installation and Configuration
            • Remote Desktop with vnc
              • Installation and Configuration
              • Running VNC as a System Service
          • Managing Running Processes
            • Listing Processes
              • ps
              • top
              • htop
            • Backgrounding and Foregrounding
              • Starting a Background Process
              • Using Foreground and Background Commands
            • Killing and Recining Processes
              • kill and killall
          • Managing Software
            • Managing Software from the Desktop
            • Going Beyond the Limitations of Software Center
              • Debian Packages
                • Advanced Package Tool (apt)
                • Repositories
                • dpkg
        • Shell Scripting
          • Variables
            • Command Substitution
            • Arguments
          • Reading User Input
          • if, else, and elif
          • BOOLEAN Logic
          • Loops
            • for Loops
            • while Loops
          • Functions
          • Local Vs Global Variables
          • Summary
        • Securing Linux
      • Windows
        • Security Hardening
Powered by GitBook
On this page
  • Discover the Default Shell
  • Open a New Shell
  • Configure a New Default Shell

Was this helpful?

  1. Core Technical Skills
  2. Core Skills
  3. Linux
  4. Getting to Know Linux
  5. Using the Shell

Choose your Shell

PreviousShells, Terminals, and Virtual ConsolesNextShell Commands

Last updated 1 year ago

Was this helpful?

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.

As we touched on earlier, there's a trend happening where some Linux distributions are gravitating towards zsh, giving bash a bit of a sidestep. Apple have made this call within MacOS.

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 $SHELL

This will display the contents of the $SHELL environment variable, which will display the shell the current user is running.

We will examine shell variables more closely a little later.

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.

If you come across entries like nologin or /bin/false, that's a hint that the account doesn't use an interactive shell. These accounts aren't intended for human use; they're non-interactive and mainly there to keep the system ticking along.

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 USERNAME

The 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/noshell

Open a New Shell

To try a different shell, simply type the name of that shell. Examples include:

  • ksh

  • tcsh

  • csh

  • sh

  • dash

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.

Different shells come with their own set of bells and whistles. It's worth having a look around to see what each one offers. As you get more comfy with Linux, you might find you'll prefer one shell for certain tasks, and another for something else entirely.

Give it a bash... (sorry)

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 USERNAME

or

chsh --shell /bin/sh USERNAME

Either of these will set the default shell to be /bin/sh for the user you specify.

Whilst it is not recommended, you could manually edit the /etc/passwd file with a text editor, but this invites complication if your edit goes sour.

Viewing the contents of /etc/passwd
A list of selectable shells in Kali Linux