Used to change the shell used when logging into the system
chsh command is used to change the shell used when logging into the system. If no parameters and user name are specified, chsh will be set in response.
chsh(options)(parameters)
-s<shell name> or --shell<shell name>: Change the system's default shell environment. ;
-l or --list-shells: List the shell list currently available in the system;
-u or --help: online help;
-v or -version: Display version information.
Username: The user whose default shell is to be changed.
Two ways to check which shells are installed on the system:
The first:
[rocroket@localhost ~]$ chsh -l
/bin/sh
/bin/bash
/sbin/nologin
/bin/zsh
The second type:
[rocroket@localhost ~]$ cat /etc/shells
/bin/sh
/bin/bash
/sbin/nologin
/bin/zsh
In fact, chsh -l
is also used to view this file.
View the shell currently in use:
[rocroket@localhost ~]$ echo $SHELL
/bin/bash
Note that SHELL must be capitalized. As you can see, the shell currently used is /bin/bash
Change my shell to zsh:
[rocroket@localhost ~]$ chsh -s /bin/zsh
Changing shell for rocrocket.
Password:
Shell changed.
[rocroket@localhost ~]$
Use chsh plus option -s
to modify the login shell! You will find that after you execute echo $SHELL
, the output is still /bin/bash
. This is because you need to restart your shell to fully embrace zsh. chsh -s
actually modifies the line corresponding to your user name in the /etc/passwd
file. Let’s check it out now:
[rocrocket@localhost ~]$ cat /etc/passwd|grep ^rocrocket
rocrocket500:500:rocrocket,China:/rocrocket/PSB/home:/bin/zsh
You can find that the last part of the output content has become /bin/zsh
. The next time you restart, Linux will read this command to start the shell!
Modify shell back to /bin/bash:
[rocroket@localhost ~]$ chsh -s /bin/bash
Changing shell for rocrocket.
Password:
Shell changed.