Change my default shell in Linux using chsh

last updated in Categories , , , , , ,

How do I change my default shell in Linux?

Say you need to change your shell in Linux from the default set up or installation. You need to use the chsh command. This page shows how to change the default shell in Linux using the CLI.


How to Change my default shell

  1. First, find out the available shells on your Linux box, runcat /etc/shells
  2. Type chsh and press Enter key
  3. You need to enter the new shell full path. For example, /bin/ksh
  4. Log in and log out to verify that your shell changed corretly on Linux operating systems.

Let us see all commands in details.

List your shells in Linux

Run the following cat command on the /etc/shells file:
cat /etc/shells
Of course, we can use the grep command/egrep command to find out if particular shell such as zsh or fish installed or not, run:
grep "zsh" /etc/shells
grep "fish" /etc/shells

How to list the available shells on your Linux desktop with cat command

Find out your current shell name

Execute any one of the following command to find the current shell instance:
ps -p $$
printf "My current shell - %s\n" "$SHELL"
grep "^${USER}" /etc/passwd
How do I check which shell I am using on Linux

Changing default shell from bash to ksh

To change your shell to zsh with chsh, run:
type -a zsh ## find path to ksh ##
chsh -s /bin/zsh ## change bash to ksh ##

Verify it:
grep "^${USER}" /etc/passwd
Log out and log in again. One can close the Terminal app and reopen it or use the su command as follows”
su - vivek
How to change my default shell in Linux using chsh command

Changing back your shell to bash with chsh

Want to reverse changes? Try:
type -a bash
chsh -s /bin/bash
## replace vivek with actual username ##
grep '^vivek' /etc/passwd
su - vivek

Getting help about the chsh command

Type any one of the following command at the CLI:
man chsh
chsh --help
The options are as follows:

  • -h : Display help message and exit.
  • -R CHROOT_DIR : Apply changes in the CHROOT_DIR directory and use the configuration files from the CHROOT_DIR directory.
  • -s /path/to/SHELL : The name of the user’s new login shell. Setting this field to blank causes the system to select the default login shell.


You learned about changing your default shell with chsh command. See shadow-utils home page for more info here.

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.