Many Linux distributions ship Bash as the default login shell, but if you want to replace it with another shell like ZSH or Fish, then you can use the chsh command to change the existing or specific user login shell.
In this article, you will learn the usage of the chsh command with practical examples.
|Description||Chsh (Change Shell)|
|Root or Sudo Privileges||Yes|
|Host System and Architecture||Ubuntu 22.10 (x64)|
|OS Compatibility||Ubuntu, Manjaro, Fedora, etc.|
Syntax of the Chsh Command
The chsh command takes two arguments: one is the option, and the other is the login (username).
$ chsh [OPTION] [LOGIN]
The following is the list of known options:
|Take the path of the shell that will be used as a replacement for an existing or specified user login shell.|
|Apply the change and use the configuration files from the “|
|Display the help section.|
/etc/passwd” file will be modified when the user login shell is changed.
Listing the Existing Shells
The only restriction applied while changing the default login shell is that the new login shell path must be listed in the “
/etc/shells” file, which can be checked using the cat command.
$ cat /etc/shells
If your new login shell path is not present in the above list of shells, then only the root user has permission to change the login shell by adding any value (referring to the shell path) while changing the user’s login shell.
An account with a restricted login shell also does not have permission to change its login shell; the only option is to ask another privileged user to change it for them.
Changing the User’s Login Shell (Interactive Mode)
The following command, without specifying the username with the “
-s” flag, will change the login shell for the currently logged-in user in interactive mode by asking for a new shell path.
Changing another user’s login shell requires root or sudo privileges; if you have them, then specify their username to change their existing login shell in interactive mode.
$ sudo chsh jake
The above command will replace the “jake” user login shell with the “
Changing the User’s Login Shell (Non-Interactive Mode)
Use the “
-s” flag with the new login shell path (without specifying any username) to change the currently logged-in user login shell in non-interactive mode.
$ chsh -s $(which zsh) #OR $ chsh -s /bin/zsh
To change another user’s login shell, specify their username as root or sudo user.
$ sudo chsh -s $(which zsh) jake #OR $ sudo chsh -s /bin/zsh jake
Reflecting the New Login Shell Changes
Restart the system or logout and login to reflect the new login shell changes for the current or specified user.
Then verify their existing shell using the following command:
$ echo $SHELL #OR $ echo $0
[Extra Tip] Changing into the Unspecified/Invalid Shell
If the new login shell path is not present in the “
/etc/shell” file, then you will get the following error while changing the current user login shell.
$ ls -l /bin/ksh
Once you have the binary path of the new login shell, use that path with the chsh command as a root or sudo user.
$ sudo chsh -s /bin/ksh
The above command will change the login shell of the currently logged-in user. To change the login shell of another user, just specify their username after the shell path.
That’s all about the chsh command that an informed Linux user should know.
If you are facing any difficulty while changing the shell or have a tip that should be added to this article, then feel free to tell us in the comment section.