{"id":368,"date":"2011-10-21T14:27:17","date_gmt":"2011-10-21T12:27:17","guid":{"rendered":"http:\/\/www.mediamill.de\/blog\/?p=368"},"modified":"2011-10-21T14:25:37","modified_gmt":"2011-10-21T12:25:37","slug":"active-directory-ldaps-zugriff-mit-ldapsearch-unter-linux","status":"publish","type":"post","link":"https:\/\/www.mediamill.de\/blog\/2011\/10\/21\/active-directory-ldaps-zugriff-mit-ldapsearch-unter-linux\/","title":{"rendered":"Active Directory LDAPS Zugriff mit ldapsearch unter Linux"},"content":{"rendered":"<p>Mit dem Befehl ldapsearch kann man LDAP-Abfragen an einen LDAP-Server stellen und damit Verzeichnisinformationen ermitteln. Da die meisten Active Directory keine anonyme Anfragen erlauben, ben\u00f6tigt man ein Dienstkonto im Active Directory, das die n\u00f6tigen Rechte f\u00fcr die erforderlichen LDAP-Anfragen besitzt.<\/p>\n<p>Der grunds\u00e4tzliche Syntax einer LDAP-Abfrage mit ldapsearch lautet:<\/p>\n<p class=\"codeblock\">ldapsearch -x -D &#8222;USERNAME@ADDOMAIN&#8220; -w &#8222;DIENSTKONTOPASSWORT&#8220; -b &#8222;searchbase&#8220; -H LDAPSERVERURL &#8222;FILTER&#8220; PROPERTY1 PROPERTY2 PROPERTYN<\/p>\n<p>-x = Use simple authentication instead of SASL<br \/>\n-D = Use the Distinguished Name binddn to bind to the LDAP directory<br \/>\n-w = Use passwd as the password for simple authentication<br \/>\n-b = Use searchbase as the starting point for the search instead of the default<br \/>\n-H = Specify URI(s) referring to the ldap server(s)<\/p>\n<p>FILTER = Die eigentliche LDAP-Abfrage<br \/>\nPROPERTYX = Propertys der Objekte, die im Ergebnis angezeigt werden sollen<\/p>\n<p>Beispiel:<\/p>\n<p class=\"codeblock\">ldapsearch -x -D &#8222;ldap@domain.local&#8220; -w &#8222;badladappasswort&#8220; -b &#8222;dc=domain,dc=local&#8220; -H &#8222;ldaps:\/\/dc.domain.local:636&#8220; &#8222;(sn=USERNAME)&#8220; description dn<\/p>\n<p>Obige Abfrage ermittelt die description und den dn des Accounts USERNAME.<\/p>\n<p>Um bei ldapsearch nicht immer alle Parameter f\u00fcr die Verbindung angeben zu m\u00fcssen, kann man in seinem Homeverzeichnis eine Datei namens .ldaprc anlegen.<\/p>\n<p class=\"codeblock\">#Beispielinhalt:<br \/>\nURI ldaps:\/\/dc.domain.local:636 #Liste mit LDAP Servern (Parameter -H)<br \/>\nBASE dc=domain,dc=local #Search Base DN (Parameter -b)<br \/>\nBINDDN ldap@domain.local #Dienstkonto f\u00fcr die LDAP Verbindung (Parameter -D)<br \/>\nTLS_CACERT \/etc\/ssl\/certs\/rootca.pem #CA Zertifikat der Root CA des DC SSL Zertifikats<\/p>\n<p>Um nicht jedes Mal das Passwort f\u00fcr die Verbindung LDAP-Verbindung angeben zu m\u00fcssen, kann man eine Datei mit dem Passwort erstellen und diese bei ldapsearch mit der Option -y angeben.<\/p>\n<p>Die Passwortdatei muss man <a title=\"ldapsearch -y schl\u00e4gt mit der Fehlermeldung \u201cldap_bind: Invalid credentials (49)\u201d fehl\" href=\"http:\/\/www.mediamill.de\/blog\/?p=361\">zwingend<\/a> ohne Steuerzeichen erstellen. Dies gelingt z.B. mit dem Befehl echo und dem Parameter -n.<\/p>\n<p class=\"codeblock\">echo -n DIENSTKONTOPASSWORT &gt; .ldappasswd<\/p>\n<p>So sieht nun der verk\u00fcrzte Syntax der ldapsearch Anfrage aus:<\/p>\n<p class=\"codeblock\">ldapsearch -x -y .\/.ldappasswd &#8222;(sn=USERNAME)&#8220; description dn<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Mit dem Befehl ldapsearch kann man LDAP-Abfragen an einen LDAP-Server stellen und damit Verzeichnisinformationen ermitteln. Da die meisten Active Directory keine anonyme Anfragen erlauben, ben\u00f6tigt man ein Dienstkonto im Active Directory, das die n\u00f6tigen Rechte f\u00fcr die erforderlichen LDAP-Anfragen besitzt. Der grunds\u00e4tzliche Syntax einer LDAP-Abfrage mit ldapsearch lautet: ldapsearch -x -D &#8222;USERNAME@ADDOMAIN&#8220; -w &#8222;DIENSTKONTOPASSWORT&#8220; -b [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[47,48,5],"tags":[],"class_list":["post-368","post","type-post","status-publish","format-standard","hentry","category-active-directory","category-ldap","category-linux"],"_links":{"self":[{"href":"https:\/\/www.mediamill.de\/blog\/wp-json\/wp\/v2\/posts\/368","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mediamill.de\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mediamill.de\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mediamill.de\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mediamill.de\/blog\/wp-json\/wp\/v2\/comments?post=368"}],"version-history":[{"count":6,"href":"https:\/\/www.mediamill.de\/blog\/wp-json\/wp\/v2\/posts\/368\/revisions"}],"predecessor-version":[{"id":405,"href":"https:\/\/www.mediamill.de\/blog\/wp-json\/wp\/v2\/posts\/368\/revisions\/405"}],"wp:attachment":[{"href":"https:\/\/www.mediamill.de\/blog\/wp-json\/wp\/v2\/media?parent=368"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mediamill.de\/blog\/wp-json\/wp\/v2\/categories?post=368"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mediamill.de\/blog\/wp-json\/wp\/v2\/tags?post=368"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}