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.
- How to find out which shell is in use in Linux (84.8%)
- Linux PowerShell Basics (Beginner's Guide) (65.2%)
- How to run small Python code in Bash (58.7%)
- Warning: apt-key is deprecated (SOLVED) (58.7%)
- How to install PowerShell in Linux Mint (56.5%)
- What program to open .docbook files (DocBook) (RANDOM - 50%)