Basic Operations
Default Shell
If you start a new Shell in the current terminal (e.g., switching from Bash to Zsh),
this command still displays the default login Shell, which is configured in /etc/passwd
.
On macOS, the default Shell information is typically stored in the user account settings,
not in the /etc/passwd
file. Starting from macOS Catalina (10.15), the default shell has been changed to zsh
,
previously the default Shell was bash
. You can view the default shell using the following method.
Current Shell
$0
in Shell returns the Shell name when running, and returns the script name/path when running in a script.
The preceding hyphen -
indicates that this Shell is the user’s login Shell.
You can also use the ps
command to view the process status.
If you start a new Shell in the current terminal (switching from Bash to Sh), the above two methods will display sh
.
Supported Shells
Change Default Shell
The content in /etc/passwd
will be updated after modification.
chsh
Modifying the login Shell of the current user will require entering the user password.
Using the root user or sudo can also modify the login Shell of other users.
Note: If we enter a non-existent Shell.
It checks whether the entered Shell is in the /etc/shells
file, preventing login failures due to entering an invalid Shell.
usermod
Using this command requires the root user or a user with sudo privileges.
Note
usermod does not check the validity of the Shell, it is not recommended to use.
The above command will not error, but will cause the kuga user to be unable to log in.
Add sudo Privileges
View the list of members of the sudo group.
Give the user sudo group privileges, which requires root execution.
Do Not Edit Passwd
If you accidentally write the configuration incorrectly, it is very likely to cause the entire system to be unable to log in.
Avoid Using Root
I accidentally changed the login Shell of root to zsh, but Ubuntu did not have zsh installed, so root could not log in. Fortunately, I had another user with sudo privileges, so I could log in normally and successfully changed root’s Shell back. If you’re unlucky and don’t have a user with sudo privileges, it would be troublesome.