How to change shell in linux

How to change shell in linux

3 Ways to Change a Users Default Shell in Linux

In this article, we will describe how to change a user’s shell in Linux. The shell is a program that accepts and interprets commands; there are several shells such as bash, sh, ksh, zsh, fish and many other lesser known shells available on Linux.

Bash (/bin/bash) is a popular shell on most if not all Linux systems, and it’s normally the default shell for user accounts.

There are several reasons for changing a user’s shell in Linux including the following:

A login shell can be accessed from a text based interface or via a SSH from remote Linux machine. However, if you login via a graphical user interface (GUI), you can access the shell from a terminal emulators like xterm, konsole and many more.

Let’s first list all available shells on your Linux system, type.

Before you proceed any further, note that:

Now let’s discuss three different ways to change Linux user shell.

1. usermod Utility

In this example, we’ll first check user tecmint’s account information to view his default login shell and then change its login shell from /bin/sh to /bin/bash as follows.

How to change shell in linux. Смотреть фото How to change shell in linux. Смотреть картинку How to change shell in linux. Картинка про How to change shell in linux. Фото How to change shell in linuxChange User Shell using Usermod

2. chsh Utility

How to change shell in linux. Смотреть фото How to change shell in linux. Смотреть картинку How to change shell in linux. Картинка про How to change shell in linux. Фото How to change shell in linuxChange User Shell Using chsh

The two methods above all modify the shell specified in /etc/passwd file which you can edit manually as in the third method below.

3. Change User Shell in /etc/passwd File

In this method, simply open the /etc/passwd file using any of your favorite command line text editors and change a specific users shell.

How to change shell in linux. Смотреть фото How to change shell in linux. Смотреть картинку How to change shell in linux. Картинка про How to change shell in linux. Фото How to change shell in linuxChange User Shell in Passwd File

When your done editing, save and close the file.

Do not forget to read these related topics:

In this article, we described various ways of changing a user’s shell in Linux. To share any thoughts with us, use the comment section below.

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

How to change shell in linux. Смотреть фото How to change shell in linux. Смотреть картинку How to change shell in linux. Картинка про How to change shell in linux. Фото How to change shell in linux

We are thankful for your never ending support.

How to Change Shell in Linux

This quick tutorial shows how to check the running shell, available shell in the system and how to change the default shell in Linux.

You probably are already aware that there are several shell available on Linux and other Unix-like systems. Bash is the default shell on almost all the Linux distributions but there are some other popular shells available such as:

Some of the shells provide additional features in a more user-friendly way. Take Fish shell for example. It partially starts showing you command hints based on your previous typed command. It’s quite handy if you don’t want remember the Linux terminal shortcuts all the time.

Let’s see a few things around shell in your Linux system.

How to know the default shell?

To know the default shell set for you in your Linux system, you can check the SHELL environment variable. Usually, the default shell is bash and it is shown like this:

How to see what shell are you currently using?

There is no single method that will tell you which shell you are using with 100% accuracy.

How to see all the shells available on your Linux system?

All the shells available on your Linux systems are listed in the file /etc/shells. You can use cat command or less command to view the content of the file.

How to change the shell to use another one?

If you want to use a different shell, you can simply type its name and you’ll be logged into the new shell. For example, if you install zsh and want to use it, you can simply use:

You can enter exit to exit from the new shell and return to the previous one.

How to change the default shell in Linux permanently?

Suppose you liked the Fish shell a lot and you want to use it as your default shell so that every time you open the terminal or ssh into the system, you are using it instead of the default bash shell.

You must log out of the system so that the changes take into effect otherwise you’ll think that running chsh didn’t change the shell.

Which shell do you like?

Now that you know how to change shell, you may also read how to change users in Linux.

I hope this little article helped you to change the shell in Linux. If you have thought about changing the default shell, perhaps you use something other than the bash shell. Which shell is it? Why do you prefer it over the others?

How To Change Default Shell In Linux

In most Linux systems, the default shell is bash but we can change that to any other shell-like zsh, fish, sh, and any other. In this article, we are going to show how to change that default shell to any other shell in Linux systems. To change the user’s shell, first, let’s find the current shell. There are many ways by which we can change the shell of any user on a Linux system. We are going to see three methods of changing the user’s shell.

Find your current shell name

In Linux systems, there is one file which is /etc/passwd. The /etc/passwd file stores essential information of user accounts, which is required during login. By using this file we can identify the current user login shell.

We are going to see the current user information in the /etc/file using the following command:

In the above image we can see that the user nishant (current user) has home directory /home/nishant and the shell is /bin/sh

List your shells in Linux

Now to change the shell, first, we need to see which shells are installed on the system. We can check installed shells using the following command :

This will show all shells as follows:

How to change shell in linux. Смотреть фото How to change shell in linux. Смотреть картинку How to change shell in linux. Картинка про How to change shell in linux. Фото How to change shell in linux

Before moving further, first understand who can change the user shell

Changing default sh shell to bash

Using usermod command

usermod is a command that modifies the system account files. usemod can change the shell of Users by modifying file /etc/passwd. usermod command provides the -s or –shell option to change the user’s login shell.

In this example, we are going to change the shell of a user named nishant. We are going to change the shell from /bin/sh to /bin/bash of user nishant using usermod command.

With usermod command mention shell and username after –shell option.

Now you can see the shell use changed. In the above commands, replace nishant with the user name whose shell has to change.

Using chsh Utility

How to change shell in linux. Смотреть фото How to change shell in linux. Смотреть картинку How to change shell in linux. Картинка про How to change shell in linux. Фото How to change shell in linux

Change User Shell to /etc/passwd File

As we see in the above two methods, the usermod command and chsh utility modify the /etc/passwd file and change the user shell. We can do that manually also by editing the /etc/passwd file. Just change the shell after the username and home directory in the /etc/passwd file and save the file.

How to Change the Default Shell in Linux System

Under the Linux operating system environment, a shell can be described as a program that takes user inputs from the computer keyboard in form of commands and interprets them with the aim of yielding immediate execution results or leading to another program execution instance.

As you familiarize yourself with Linux, you will get the opportunity to meet and interact with many Linux-oriented shell environments like bash, ksh, fish, sh, and zsh. Due to the popularity of Bash Shell, there is a high chance that you are using it now as the default shell on your Linux system.

Why Change Default Shell in Linux?

Opting to change the default Linux shell makes sense due to the following reasons:

Listing Valid Login Shells in Linux System

Before you consider changing the default shell in your Linux system, first list the valid login shells that are at your Linux OS disposal:

How to change shell in linux. Смотреть фото How to change shell in linux. Смотреть картинку How to change shell in linux. Картинка про How to change shell in linux. Фото How to change shell in linuxList Default Linux Login Shells

Before we proceed and demonstrate how we can switch from one Linux shell to another, take note of the following:

Ways of Changing the Default Linux Shell

We will be looking at the following approaches to change the default shell in Linux.

Method 1: Using the usermod Utility

The following command checks the account information such as default shell for user dnyce.

How to change shell in linux. Смотреть фото How to change shell in linux. Смотреть картинку How to change shell in linux. Картинка про How to change shell in linux. Фото How to change shell in linuxCheck User Linux Shell

As you can see, the dnyce user is using bash as the default Linux shell. To change from /bin/bash to /bin/dash, execute the following command:

How to change shell in linux. Смотреть фото How to change shell in linux. Смотреть картинку How to change shell in linux. Картинка про How to change shell in linux. Фото How to change shell in linuxChange User Linux Shell

Method 2: Using the chsh Utility

Let us change the current shell from /bin/dash to /bin/rbash.

How to change shell in linux. Смотреть фото How to change shell in linux. Смотреть картинку How to change shell in linux. Картинка про How to change shell in linux. Фото How to change shell in linuxChange User Shell in Linux

Method 3: Using /etc/passwd File

Open the /etc/passwd file and edit it to your preferred default Linux shell.

How to change shell in linux. Смотреть фото How to change shell in linux. Смотреть картинку How to change shell in linux. Картинка про How to change shell in linux. Фото How to change shell in linuxChange Linux User Shell

Save the file and confirm the changes took place with the following command:

How to change shell in linux. Смотреть фото How to change shell in linux. Смотреть картинку How to change shell in linux. Картинка про How to change shell in linux. Фото How to change shell in linuxCheck Linux User Shell

We have understood the need for changing the default Linux shell and implemented some practical methodologies for achieving the said goals.

How To Change The Default Shell In Linux (Bash, Zsh, Fish, Etc.)

How to change shell in linux. Смотреть фото How to change shell in linux. Смотреть картинку How to change shell in linux. Картинка про How to change shell in linux. Фото How to change shell in linux

This article explains how to change the default shell in Linux. Using this you can set Bash, sh, Zsh, Csh, Fish, etc. as your shell.

The article includes instructions for changing the login shell from the command line using chsh, or changing the shell only for a particular terminal application. While the article is targeted at Linux users, this should also work on other Unix-like systems.

How to change the default login shell using chsh (from the command line)

It’s important to note that using chsh, a normal user may only change the login shell for the current account, while the superuser may change the login shell for any account, including the root account. Also, the default behavior for non-root users is to accept only shells listed in the /etc/shells file, and issue a warning for root user.

So before changing your shell, list all the shells listed in the /etc/shells file from your Linux system by using the following command:

Example with output:

If the shell you want to use is not listed here, it may not be installed on your system. So install it (for example, install Zsh on Debian / Ubuntu / Linux Mint / Pop!_OS using: sudo apt install zsh ) and check again.

To change the shell for your user, run:

This runs chsh in an interactive mode, asking you for the password, then listing your current shell (most Linux distributions use Bash as the default shell) and asking you to enter a value for your new shell. Here’s the command with its output:

To change your shell, type the path to the new shell (which exists in /etc/shells ) and press the Enter key.

For example, to change the shell for the current user from Bash to Zsh:

E.g. to change the shell to Zsh:

After changing your account’s shell, logout and re-login to use the new shell.

Change the shell for your user in a terminal application

As a side note, you may also change the current shell (non-permanent change) by typing the shell command you want to use in a terminal (e.g. if you type «zsh», you’ll switch to using Zsh for that session; exit by typing «exit».).

For terminals that allow running a custom shell you should also find an option that allows running the command as a login shell (usually called just that: «Run command as a login shell»). To read on the differences between a login shell and an interactive shell, see this page.

Источники информации:

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *