How to Change Linux Login Shell Using chsh Command
The chsh (change shell) command in the Linux operating
system is the dedicated utility used to view and change a user's default
login command interpreter. This article explains the core purpose of the
chsh command, how it securely modifies the system's user
configuration files, and how to use it with proper syntax to switch
between different shells like Bash, Zsh, and Fish.
The Purpose of the chsh Command
When a user logs into a Linux system via the console, SSH, or a
terminal emulator, the system launches a default command-line
interpreter defined for that specific user account. The primary purpose
of the chsh command is to modify this setting by updating
the user's entry in the /etc/passwd configuration file.
Instead of requiring users or administrators to manually edit
/etc/passwd using a text editor—which introduces the risk
of syntax errors, file corruption, or permission
issues—chsh provides a safe, interactive, or
command-line-driven method to perform this change.
Key Security and Validation Features
The chsh command enforces critical security rules during
the process:
- Restricted Shell Verification: Standard (non-root)
users can only change their shell to one of the authorized paths listed
in the
/etc/shellsfile. If a user attempts to select a shell not listed in this file, the system rejects the operation. - Permission Boundaries: Regular users are only
permitted to change their own login shell and must authenticate with
their password to do so. Only the superuser (
root) can change the login shell of another user or assign an unlisted shell path.
How to Use the chsh Command
1. Identify Your Current Shell
Before changing shells, verify which shell you are currently using:
echo $SHELL2. View Available Shells
Check the list of valid, installed shells available on the system:
cat /etc/shellsAlternatively, on many distributions, you can list them directly using:
chsh -l3. Change Your Default Shell
To change your own login shell, use the -s flag followed
by the absolute path of the desired shell:
chsh -s /bin/zshIf run without any arguments, chsh operates in an
interactive mode, prompting you to enter the new shell path
directly.
4. Change Another User's Shell (Administrative)
System administrators can change the shell for any account by appending the target username to the command:
sudo chsh -s /bin/bash usernameApplying the Changes
Once executed, chsh updates the last field of the user's
line in /etc/passwd. The change does not affect currently
active terminal sessions; the user must log out and log back in for the
new default shell to take effect.