Change my default shell in Linux using chsh

ADVERTISEMENTS



How to Change my default shell

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

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.

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



Execute any one of the following command to find the current shell instance:

ps -p $$

OR

printf "My current shell - %s

" "$SHELL"

OR

grep "^${USER}" /etc/passwd



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



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

OR

chsh --help

The options are as follows:

-h : Display help message and exit.

: 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.

: 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.

Conclusion

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