How to change the login shell in Linux. chsh instruction
February 20, 2021
What is a login shell for?
In practical terms, the selected login shell determines the default shell for the user. Although, of course, nothing prevents you from running any other shell installed on your system.
How to find out what shells are installed on the system
To change the default shell for a user, you need to know which shells are available and what they are named correctly.
One way to find out the correct shell names and paths to executable files is to run the following command:
But the previous command does not work on all distributions (works on Arch Linux, but does not work on Debian derivatives).
Therefore, you can use the universal method - look at the contents of the /etc/shells file:
The shells file contains the paths to the active login shells.
/etc/shells is a text file that contains the full paths to valid login shells. This file is viewed by chsh and can be requested by other programs.
Keep in mind that there are programs that access this file to find out if the user is a regular user; for example, FTP daemons have traditionally denied access to users with shells not included in this file.
Program for changing default user shell - chsh
chsh - Change the user's login shell permanently.
If you want to temporarily change the shell, then install it and run it. Examples of commands for launching various shells:
sh bash pwsh dash zsh
chsh is used to change the login shell. If shell is not listed on the command line, chsh prompts for it.
chsh supports non-local entries (kerberos, LDAP, etc.) if linked to libuser, otherwise use ypchsh, lchsh, or any other implementation for non-local entries.
sudo chsh -s SHELL
As the SHELL, you need to specify one of the shells, as they are listed in the /etc/shells file.
chsh will accept the full path to any executable file on the system.
The default behavior for non-root users is to accept only shells listed in the /etc/shells file and issue a warning to the root user. It can also be configured at compile time to only issue a warning to all users.
Changing shell with usermod
The usermod utility with the -s option changes the shell for the specified user.
For example, to block the root user, use the following command:
sudo usermod -s /usr/sbin/nologin root
To assign a Bash shell to the root user:
sudo usermod -s /usr/bin/bash root
To assign a ZSH shell to the root user:
sudo usermod -s /usr/bin/zsh root
- How to find out which shell is in use in Linux (84.4%)
- Linux PowerShell Basics (Beginner's Guide) (65.6%)
- How to convert a string to uppercase in Bash (64.6%)
- How to convert a string to lowercase in Bash (64.6%)
- How to disable “did you mean...” feature in Linux shell (64.6%)
- How to change the VeraCrypt interface language in Linux (RANDOM - 50%)