Change my default shell in Linux using chsh

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

Find out your current shell name

Execute any one of the following command to find the current shell instance:
ps -p $$
OR
printf "My current shell - %s\n" "$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.
  • -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.

Conclusion

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


🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 0 comments... add one


CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
0 comments… add one

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum