Still, many Linux distributions ship Bash as the default login shell, but they can’t stop you from playing with another shell.
The following are some reasons that might force users to change their login shell:
- Blocking or disabling the user’s login using the nologin shell in Linux.
- Utilizing the additional features or functionality of another shell.
- Adding the user to the restricted bash shell.
- Switching to a shell that supports the shell script and executes it before the user login.
While creating the user account using the useradd or adduser command, you have the “
-s” or “
--shell” flag to specify a custom login shell apart from the default.
Still, if you forget to do that, you can follow this article to learn different ways to change the user’s login shell in Linux.
|Description||Changing User’s Login Shell|
|Root or Sudo Privileges||Yes|
|Host System and Architecture||Ubuntu 22.10 (x64)|
|OS Compatibility||Ubuntu, Manjaro, Fedora, etc.|
|Prerequisites||printenv, echo, cat, usermod, chsh, vim, nano|
The following are a few things you should know while changing the user’s login shell.
- All the commands mentioned in this article will modify the “
- Users can only change to another shell that is listed in the “
/etc/shells” file; otherwise, root or sudo users have the privilege to change to an unlisted shell.
- You can easily manage to change your own existing shell.
- Changing another user’s login shells requires the root or sudo account.
- If the account has a restricted login shell, then only the root or another sudo user has privileges to change the login shell.
Checking the Current User’s Login Shell
Always take a note of your existing login shell before changing to another to easily revert back in the future if things do not go as expected.
Execute any one of the following commands to check your existing login shell:
$ printenv SHELL #OR $ echo $0
As you can see, I have a Bash login shell as the default in my Linux system.
List Out All the Shells in Your System
Next, you need to make sure that the new login shell that you are about to switch is present in the “
/etc/shells” file by reading it using the cat command.
$ cat /etc/shells
Changing the User’s Login Shell
Once you have found your existing login shell and the new shell is present in the “
/etc/shells” file, you can follow any one of the following methods to change your existing login shell.
$(which shellname)” command to pass the shell path; however, you can directly specify the full path without using the which command unless the path is present in the “
Method 1: Using the Usermod Command
The usermod command is used to change user account information by modifying the “
/etc/passwd” file and you can specify the new login shell path to “
-s” or “
--shell” flag with username to change.
For example, the following command will change the login shell from Bash to ZSH for the “
$ grep linuxtldr /etc/passwd #Checking the current login shell $ sudo usermod -s $(which zsh) linuxtldr #Changing to ZSH login shell $ grep linuxtldr /etc/passwd #Checking the record updated with new login shell
Method 2: Using the Chsh Command
The chsh command is a special tool to modify the user’s login shell using the “
-s” or “
$ grep linuxtldr /etc/passwd #Checking the current login shell $ chsh -s $(which zsh) linuxtldr #Changing to ZSH login shell $ grep linuxtldr /etc/passwd #Checking the record updated with new login shell
Method 3: Modifying /etc/passwd File
In the previous two methods, you learn to change login shell using command-line utility but behind the scenes both are modifying the “
/etc/passwd” file with a new login shell path that you can also do manually using your choice of text editor like Vim or Nano.
$ sudo vim /etc/passwd
Once you are done with editing, save and close the file.
When you change the user’s login shell the changes will be applied immediately in the “
/etc/passwd” file; however, it is always recommended to logout and login to apply the changes properly.
So, that was all the possible ways to change the user’s login shell, except if you have any more tricks, then do let us know in the comment section.