Verify shell with getent passwd
In the previous steps, you learned how to view the /etc/passwd
file directly and list available shells. Now, let's use another command, getent
, to retrieve user information, including the shell.
The getent
command is a utility that gets entries from Name Service Switch (NSS) databases, which can include /etc/passwd
, /etc/group
, and others. It's a more standardized way to retrieve user information compared to directly reading /etc/passwd
, as it can also query network-based user databases.
To get the entry for the labex
user from the passwd
database, type the following command in your terminal and press Enter:
getent passwd labex
This command specifically requests the entry for the user labex
from the passwd
database. The output will be similar to the line you saw when using cat /etc/passwd
:
labex:x:5000:5000:LabEx user,,,:/home/labex:/usr/bin/zsh
Again, the last field /usr/bin/zsh
confirms the default shell for the labex
user.
Using getent
is often preferred in scripts or for querying systems that might use centralized authentication systems (like LDAP) instead of just local files. For simple checks on a local system, both cat /etc/passwd
and getent passwd <username>
work.
You have now successfully used three different methods to understand user shells in Linux: directly viewing /etc/passwd
, listing available shells with chsh -l
, and querying user information with getent
.
Click Continue to complete this lab.