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.
Tutorial Details
Description | Chsh (Change Shell) |
Difficulty Level | Low |
Root or Sudo Privileges | Yes |
OS Compatibility | Ubuntu, Manjaro, Fedora, etc. |
Prerequisites | chsh |
Internet Required | No |
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:
Options | Description |
---|---|
"-s", "--shell" | Take the path of the shell that will be used as a replacement for an existing or specified user login shell. |
"-R", "--root" | Apply the change and use the configuration files from the “CHROOT_DIR ” directory. |
"-h", "--help" | Display the help section. |
The “/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
Output:
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.
$ chsh
Output:
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
Output:
The above command will replace the “jake” user login shell with the “/bin/zsh
” shell.
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
Output:
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
Output:
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
Output:
[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.
In this situation, you have to find the binary path of that shell using the which command or search in the “/bin/
” directory using the find or ls commands.
$ ls -l /bin/ksh
Output:
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
Output:
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.
Join The Conversation
Users are always welcome to leave comments about the articles, whether they are questions, comments, constructive criticism, old information, or notices of typos. Please keep in mind that all comments are moderated according to our comment policy.