Bootstrap FreeKB - Linux Commands - List LDAP and local user accounts using the getent passwd command
Linux Commands - List LDAP and local user accounts using the getent passwd command

Updated:   |  Linux Commands articles

There are a few commands that can be used to determine if a user account exists.

The getent (get entries) command is similar to the cat command, in that it lets you view the contents of a file. However, the getent command is different from the cat command, in that it can query multiple sources. One of the most common uses of the getent command is when a system is configured with both local authentication and LDAP authentication. In this scenario, the local users will be listed in the /etc/passwd file, and the LDAP users will be on the LDAP server. The getent passwd command will display all of the local user accounts in /etc/passwd and all of the users on the LDAP server. In this example, Bush and Clinton are local user accounts, and Reagan and Clinton are users on the LDAP server.

~]# getent passwd
bush:x:1005:1006::/home/ford:/bin/bash
obama:x:1006:1007::/home/carter:/bin/bash
reagan:x:::::
clinton:x:::::

 

Likewise, if a system is configured with both local group accounts and LDAP group accounts, the getent group command will list both local groups and groups on the LDAP server.

~]# getent group
group1:x:1001:
group2:x:1002:
LDAPgroup:x::

 

Following are a list of common getent commands.

  • getent ahosts
  • getent ahostsv4
  • getent ahostsv6
  • getent aliases (email users)
  • getent ether (Ethernet)
  • getent group
  • getent gshadow (group passwords)
  • getent hosts
  • getent netgroup
  • gettet networks
  • getent passwd (user accounts)
  • getent protocol
  • getent rpc
  • getent services
  • getent shadow (user passwords)

 

Often, the id command is used along with the getent passwd command. In this example, John Doe's user ID is 655 and John Doe is a member of the wheel group.

~]# id john.doe
uid=655(john.doe) gid=2001(wheel) groups=2001(wheel)

 

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 6e4093 in the box below so that we can be sure you are a human.