How To Change Shell To Bash in Linux / Unix

How do I switch from a ksh shell to bash on Linux or Unix system? How to change shells on Unix-like system?

A shell is nothing but a command that provides a text-only user interface (also known as “command line interface”) for Linux, MacOS, and Unix-like operating systems. Bash shell read commands such as ls, date and others typed into a terminal and then run them. That is the primary function of bash shell.
How do I switch from an unknown shell to bash?
Tutorial details
Difficulty level Easy
Root privileges No
Requirements Linux or Unix-like OS
Est. reading time 2 minutes

How do I find out the default shell for a user?

Type the following command to find out the default shell for a user named vivek using the grep command and /etc/passwd file:
$ grep vivek /etc/passwd

$ ps -p $$
14314 pts/9 00:00:00 zsh

$ echo $0

All of the above output indicates that the shell is zsh for user named vivek in Linux operating system.

How do I see what shells are available on my system?

Type the cat command as follows:
$ cat /etc/shells

Fig.01: How to find list of available shells on Linux or Unix or MacOS?

The /etc/shells is a text file that contains the full pathnames of valid login shells. This file is consulted by the chsh command and available to be queried by other programs. Hence, only use shell names and paths mentioned in this file.

How do I switch to a bash or different shell?

Type the name at the command line and then press the enter key. In this example, to change from any shell to the bash, type:

How to change shells on a Linux or Unix-like systems?

You can change your default shell using the chsh (“change shell” ) command as follows. The syntax is:
chsh -s {shell-name-here}
chsh -s {shell-name-here} {user-name-here}
chsh -s /bin/bash
chsh -s /bin/bash vivek

You can find full path to your shell using the following command:
type -a bash
type -a zsh
type -a ksh

Please note that a normal user may only change the login shell for her own account. The superuser (root) may change the login shell for any account using the following syntax:
$ sudo chsh -s /bin/bash raj
OR use the su command instead of sudo command:
$ su -
# chsh -s /bin/bash monika

Summing up

The only restriction placed on the login shell is that the shell command name must be listed in /etc/shells file, unless the invoker is the superuser/root user, and then any value may be added. An account with a restricted login shell may not change her login shell. For this reason, placing /bin/rsh in /etc/shells is discouraged since accidentally changing to a restricted shell would prevent the user from ever changing her login shell back to its original value.

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

🐧 7 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
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 jobs killall kill pidof pstree pwdx time
Searchinggrep 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
7 comments… add one
  • Big Daddy Leroy Jan 11, 2017 @ 20:58

    getent passwd $USERNAME will provide user’s shell as well

    • David G Jan 12, 2017 @ 20:21

      First command doesn’t show the result. 2nd, 3rd and yours command provided me the shell information. Also you can change $USERNAME variable with the user name desired.

  • David G Jan 12, 2017 @ 20:16

    I have a Linux system with AD authentication; chsh command does not work for my configuration. Is there any other way to change the default change? Thanks.

    • 🐧 Vivek Gite Jan 12, 2017 @ 21:31

      AD as in active directory? Are you using bash under Windows 10? Give us more info.

  • lemonTart Jan 22, 2021 @ 18:24

    Awesome. Super helpful. Thanks.

  • Rodrigo Mar 4, 2021 @ 22:44

    Thanks a lot , you are a hero ! greetings from Goya, Corrientes , Argentina .

  • Aarón Alberich Apr 10, 2021 @ 8:36

    Very useful. You solved my problem. I had a fish shell setup by accident and wanted bash so severely. I use Docker, and bash syntax is what is mostly used with Dockerfile. This page solved my problems perfectly on a CentOS Linux 7.

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