قالب وردپرس درنا توس
Home / Tips and Tricks / How to change your default shell on Linux with chsh

How to change your default shell on Linux with chsh



  A stylized shell prompt on an Ubuntu-like Linux laptop system.
Fatmawati Achmad Zaenuri / Shutterstock

Bash is not the only Linux shell. It's easy to try out other shells, like Zsh, which is very popular. If you've found one you like, use the chsh command to make it your default shell. We'll show you how.

Why a shell is important

The shell is between you and the operating system. It provides the environment in a terminal window that allows you to type commands and run programs. The shell checks your input and determines what you want. If it can make your bids itself, it will. If it needs outside help, it searches the path and finds the programs that can do what you asked.

There are many different shells available on Linux. They all allow you to perform the same core tasks: explore the file system, work with files, launch programs and run scripts. However, they each perform these tasks in their own way and have their own special features and quirks.

Shells are usually designed by people who want things to behave in a specific way. If your thinking matches that of that designer, that scale might suit you well. Moreover, it is easy to try a new shell on Linux.

In most Linux distributions, including Ubuntu, the default shell is bash . It does a great job and is very capable. However, a different shell can make a time-saving difference that would have a big impact on your workflow. You will never know if you are not looking!

RELATED: What is ZSH and why should you use it instead of Bash?

A bucket of shells

We've covered the different Linux shells before, but here's a quick introduction to the most common:

  • bash: The Bourne again shell is the standard in many distributions .
  • rbash: This Restricted bash shell provides minimal functionality for the person or script running in it.
  • ash: The Almquist shell is a lighter version of bash.
  • dash: The Debian Alquist shell is the default shell script in Ubuntu. While bash is the default login and interactive shell, dash is used to run system processes because it is much lighter than bash .
  • zsh: The Z-scale is a modern version of the bash shell family. It offers neat improvements, such as command spelling checks and suggested corrections.
  • fish: This friendly interactive shell has been rewritten from scratch and is not derived from any of the other shell families. It is intended to be user-friendly. In addition to its many other benefits, fish offers command suggestions based on your history and the contents of the current directory, similar to predictive text.
  • ksh: The KornShell offers a particularly strong scripting language.

RELATED: What's the Difference Between Bash, Zsh, and Other Linux Shells?

View installed shells

Use this command to see which shells are installed on your computer. It simply lists the contents of the file / etc / shells :

  cat / etc / shells 

  cat / etc / shells in a terminal window.

We already mentioned it bash dash and rbash but what is sh ?

sh is the Thompson scale, written as early as 1971 by Ken Thompson of Bell Labs fame. It is no longer maintained and has long been replaced by modern shells. It is included purely to maintain compatibility with older scripts that still have the following line:

  / Bin / sh 

This instructs the system to use the shell sh to run the script. Do you really have that ancient shell on your machine and is it used to run your scripts? The command tells us which program is actually executed when you type a command.

Let's see what happens when you type sh :

  which sh 

This appears to find a binary. if we dig a little deeper we'll see that it is a symbolic link actually referring to dash the lightweight shell used to run scripts:

  ls -l / bin / sh [19659035] located in a terminal window. " width="646" height="132" src="/pagespeed_static/1.JiBnMqyl6S.gif" onload="pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);" onerror="this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);"/> 

That's a neat, lightweight way to provide a safety net for scripts that expect to find sh on modern systems.

Install Another Shell

Let's install the fish shell and set it as default for dave . On Ubuntu we type the following command:

  sudo apt-get install fish 

 sudo apt-get install fish in a terminal window.

Use pacman :

  sudo pacman -Sy fish 

 sudo pacman -Sy fish in a terminal window.

On Fedora, type the following:

  sudo dnf install fish 

 sudo dnf install fish in a terminal window.

When the installation is complete, you can check the installed shells again:

  cat / etc / shells 

 cat / etc / shells in a terminal window. "width =" 646 "height =" 197 "src =" / pagespeed_static / 1.JiBnMqyl6S.gif "onload =" pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon (this); "onerror =" this.onerror = null; pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon (this);

Our new shell appears as / usr / bin / fish . Write down that path - you will need it soon.

The environment variable $ SHELL

The environment variable $ SHELL contains the name of your current shell. We can check which one is set with echo :

  echo $ SHELL 

Let's start the fish fish:

  fish 

. Let's check again what the environment variable $ SHELL says:

  echo $ SHELL 

 echo $ SHELL in a terminal window.

The first time we use echo $ SHELL we are in the bash shell. The environment variable contains the path to the executable bash / bin / bash .

When we launch the scale fish we get a friendly welcome message and the command prompt changes. Perhaps surprisingly, the $ SHELL environment still holds the path to the executable bash / bin / bash . That's okay, this is normal.

When you start a new shell (or other program), it inherits the environment from the parent shell. So the fish shell inherits the global and exported environment variables from the bash shell. Because the value in the environment variable $ SHELL has not changed, it has the same value in the scale fish as in the scale bash .

We feed fish like any other program. We can also use exit to exit the fish shell. It closes like any other program and we return to the bash shell.

That's great to try out new shells, see what they can do and if you can handle it. You can explore before making the jump and adopt one as your favorite shell.

If you decide to make the fish - or some other shell - your default, you have to command the chsh .

The chsh command

With the chsh command you can change your default shell. The trick is that you are aware that it allows you to change both the default login and the default interactive shells. You can change one or the other or both.

Whenever you log in to get a command prompt, use the shell configured as your login shell. When you are already logged in and open a terminal window, use the shell configured to be your interactive shell. These can be the same or different shells.

Use chsh without parameters to set your login shell:

  chsh 

 chsh in a terminal window. "Width =" 646 "height =" 147 "src =" / pagespeed_static / 1.JiBnMqyl6S.gif "onload =" pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon (this); "onerror =" this.onerror = null; pagespeed.lazyLoadImages.loadIfBeable;

You will be asked for your password. Next, you need to type the path to the new shell and press Enter.

When we connect remotely to this test computer from another, we are in the fish shell as soon as we log in.

 SSH connection to the fish shell as the notification shell, in a terminal window. "width =" 646 "height =" 435 "src =" / pagespeed_static / 1.JiBnMqyl6S.gif "onload =" pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon (this); "onerror =" this.onerror = null; pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon (this);

Use ch to change your interactive shell -s (shell) option. Pass the path to the new shell on the command line:

  chsh -s / usr / bin / fish 

<img class = "alignnone wp-image-670057 size-full" data-pagespeed-lazy-src = "https://www.howtogeek.com/wp-content/uploads/2020/04/x8-4.png.pagespeed.gp+jp+jw+pj+ws+js+rj+rp+rw+ri+cp + md.ic.dfk5vr8DQ-.png "alt =" chsh -s / usr / bin / fish in a terminal window. "Width =" 646 "height =" 97 "src =" / pagespeed_static / 1.JiBnMqyl6S.gif "onload = "pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon (this);" onerror = "this.onerror = null; pagespeed.lazyLoadImages.loadIfVisibleAndMay40]

You will be asked for your password and you will be returned to the command prompt of your current shell. You must log out and log in again for the change to take effect. When you do that, you see the greeting and the fish shell command prompt.

The environment variable $ SHELL now includes the path to your new default shell:

  echo $ SHELL [19659030]  echo $ SHELL in a terminal window. "Width =" 646 "height =" 122 "src =" / pagespeed_static / 1.JiBnMqyl6S.gif "onload =" pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon (this); "onerror = "this.onerror = null; pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon (this);  

Change the shell of another user account

If you have root permissions and you can use sudo change shells of other user accounts gestation is the same as before, adding that person's username to the command line:

  sudo chsh -s / usr / bin / fish mary 

 sudo chsh -s / usr / bin / fish mary in a terminal window. "width =" 646 "height =" 97 "src =" / pagespeed_static / 1.JiBnMqyl6S.gif "onload =" pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon (this); "onerror =" this.onerror = null; pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon (this);

When mary logs in next time, she sees the new shell when she opens a terminal window.

 user mary at the fish shell command prompt, in a terminal window. "width =" 646 "height =" 77 "src =" / pagespeed_static / 1.JiBnMqyl6S.gif "onload =" pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon (this); "onerror =" this.onerror = null; pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon (this);

Everyone has a favorite

As long as you are comfortable with your choice of shell, and it works for you, that's great! Remember that it must be able to run common scripts, such as installation routines. This should not be a problem for the shells mentioned here.

You can of course also download and install a new shell, and take a test drive without making any configuration changes to your computer. When you are ready to tie the knot, chsh will perform the ceremony for you.




Source link