Link to home
Start Free TrialLog in
Avatar of Charlie_Melega
Charlie_Melega

asked on

Running an LDAP Query from command line in Linux

Hello,

I want to run an LDAP query from a command line on a linux system?.
 i.e., I want to run the following query to look up a user's DN:

(&(objectCategory=Person)(objectClass=user)(sAMAccountName=username))

How can I run this LDAP query from a linux command line and have it return query results for the provided username?

Thank You
ASKER CERTIFIED SOLUTION
Avatar of sweetfa2
sweetfa2
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Charlie_Melega
Charlie_Melega

ASKER

Thank You sweetfa2.
I've bolded a couple of variables below that I would kindly ask clarification. YourADDN is your Active Directory DN?   Not sure what the reference to @inetOrgPerson is;


ldapsearch -V -h ldapserver.host.name -b 'YourADDN' -x -s base -z 1 -l 1 '(&(objectCategory=Person)(objectClass=user)(sAMAccountName=username))' @inetOrgPerson
_____________________________________
You are correct with YourADDN.

inetOrgPerson is the list of attributes to retrieve (equivalent to person)
Hello sweefta2,

I have one final question:

I am sure I have a syntax error as when I typed what I believed to be relevant command, it simply returned a syntax page as if i typed -help.

My DC machine is named ac2.cm.loc.
My Domain is cm.loc

Based on your guidance, I attempted the following:

ldapsearch -V -h ac2.cm.loc -b 'DC=cm,DC=loc' -x -s base -z 1 -l 1 '(&(objectCategory=Person)(objectClass=user)(sAMAccountName=username))' @inetOrgPerson

Thanks for any guidance
I presume you have found your answer as you have marked this as solved.

If not, try "man ldapsearch" for other possible options.

Alternatively do a google search on ldapsearch syntax examples to give you other examples of how to do what you wish.