This article describes how to change the default Shell in Linux. Using this function, you can set Bash, sh, Zsh, Csh, Fish, etc. as shells.
This article includes instructions on using chsh to change the login shell from the command line or only for specific terminal applications. Although this article is aimed at Linux users, it should also be applicable to other Unix-like systems.
To change the default login shell, we will use
chsh, This is a command line tool for changing the login shell.
The program is modified
/etc/passwd File and set
$SHELL Environment variables. You can override the default shell in the terminal application by setting the shell in the terminal settings-see the second part of this article for details.
Note to Fedora users. Fedora does not install chsh by default. To use it, you must install a file called
util-linux-user.If you want to skip installing this package, you can use
lchsh Instead, change the login shell, which is available by default:
sudo lchsh $USER
It is important to note that with chsh, ordinary users can only change the login shell of the current account, while super users can change the login shell of any account (including the root account).In addition, the default behavior for non-root users is to only accept the
/etc/shells File and warn the root user.
Therefore, before changing the shell, please list
/etc/shells Use the following command to download files from the Linux system:
$ cat /etc/shells# /etc/shells: valid login shells/bin/sh/bin/bash/bin/rbash/bin/dash/usr/bin/tmux/bin/zsh
If the shell you want to use is not listed here, it may not be installed on the system. So please install it (for example, install Zsh on Debian/Ubuntu/Linux Mint/Pop!_OS using the following command:
sudo apt install zsh), and then check again.
To change the shell for your users, run:
chsh In interactive mode, it asks for your password, then lists your current shell (most Linux distributions use Bash as the default shell) and asks you to enter the value of the new shell. This is the command and its output:
$ chshPassword:Changing the login shell for logixEnter the new value, or press ENTER for the default Login Shell [/bin/bash]:
To change your shell, type the path of the new shell (exists in
For example, to change the current user’s shell from Bash to Zsh:
$ chshPassword:Changing the login shell for logixEnter the new value, or press ENTER for the default Login Shell [/bin/bash]: /bin/zsh
If the chsh version you are using is not started via interactive prompt after execution
chsh, Directly change the login shell for your user:
chsh -s <SHELL>
For example, change the shell to Zsh:
chsh -s /bin/zsh
After changing the shell of the account, log out and log back in to use the new shell.
To change the login shell of other users or the root user, use the root user to log in to the shell prompt as root.
sudo suWait, then run:
- To change the shell of the root account (and when prompted, enter the login shell to use and its full path):
- Change the shell of another user (this also applies to the root user, use
chsh -s <SHELL> <USERNAME>
This time we will chsh with
-s Option to directly change the login shell (will not run interactively). Here,
SHELL Is the new shell (e.g.
USERNAME Is the user for whom you want to change the shell; for example, change the shell to
/bin/zsh To users
Logix, You will use:
chsh -s /bin/zsh Logix).
You might also like: Starship is the smallest and fast Shell prompt written in Rust
You can use a different shell from the login shell (
$SHELL) For a specific terminal application, if the application allows you to set a custom shell or run a custom command instead of the default shell.
Incidentally, you can also change the current shell (non-permanent change) by typing the shell command you want to use in the terminal (for example, if you type “zsh”, it will switch to using Zsh for that session; otherwise, it will change to Current shell). Enter “exit” to exit. ).
Take the GNOME terminal as an example (used as the default terminal in GNOME and Cinnamon desktops).Open it
Preferences, Click the current active profile in the left sidebar (if it has not been changed or a new profile has not been added, it is usually called default or unnamed), and then click
Here you can set up a custom shell for this application only.Enable
Run a custom command instead of my shell Option and then
Custom command Enter the full path of the shell to be used in the field, for example
In the Xfce4 terminal, open
Preferences And in
General Label, you need to enable a file called
Run a custom command instead of my shell, Then enter the custom command below (this is the shell you want to use with this terminal, for example
Use Konsole with KDE Plasma, go to
Settings -> Edit Current ProfileAnd in
General Label, change
Command Field to the full path of the shell you want to use (again, something like:
With Guake, you can change the user shell from there
Shell Label, you will find a
Default interpreter Allow selection of any shell listed in it
For terminals that allow running custom shells, you should also find an option that allows the command to be run as a login shell (usually just called: “Run the command as a login shell”).To understand the difference between a login shell and an interactive shell, see This page.
In most cases, the settings are the same, so I won’t repeat them.However, it is worth noting that not all terminal applications have the option to allow the use of a custom shell-in this case, please use
chsh Change the command of the login shell as described above.
You might like: 179 color schemes for Gtk-based Linux terminals (Gnome terminal, Tilix, Xfce terminal, etc.)