<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>iptables and more on Linux &#187; authentication</title>
	<atom:link href="http://iptables.gen.tr/category/authentication/feed/" rel="self" type="application/rss+xml" />
	<link>http://iptables.gen.tr</link>
	<description>networking, tools in Linux and more...</description>
	<lastBuildDate>Wed, 16 Jun 2010 15:37:47 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>LDAP authentication howto</title>
		<link>http://iptables.gen.tr/2010/01/ldap-authentication-howto/</link>
		<comments>http://iptables.gen.tr/2010/01/ldap-authentication-howto/#comments</comments>
		<pubDate>Sun, 03 Jan 2010 20:35:41 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[authentication]]></category>
		<category><![CDATA[ldap]]></category>

		<guid isPermaLink="false">http://iptables.gen.tr/?p=45</guid>
		<description><![CDATA[In our previous article we have configured our systems to authenticate from an NIS server. Now we are using LDAP which is more effective and easy to manage.  Software installation isn&#8217;t within the scope of this documentation but pure configuration. Our tests systems are Redhat 5.4 but you can use this in other redhat based [...]]]></description>
			<content:encoded><![CDATA[<p>In our previous <a href="http://iptables.gen.tr/2010/01/nis-server-and-client-configuration/" target="_blank">article</a> we have configured our systems to authenticate from an NIS server. Now we are using LDAP which is more effective and easy to manage.  Software installation isn&#8217;t within the scope of this documentation but pure configuration. Our tests systems are Redhat 5.4 but you can use this in other redhat based systems. Lets start;</p>
<p>Here are the details about our setup once:</p>
<p><strong>LDAP Server: </strong>rh54srv1.iptables.gen.tr<br />
<strong>Linux client: </strong>rh54-2.iptables.gen.tr</p>
<p><strong>[LDAP configuration]</strong></p>
<p>Adjust the following lines in your /etc/openldap/slapd.conf</p>
<table style="background-color: #ffe4b5; width: 509px; height: 82px;" border="0">
<tbody>
<tr>
<td><strong>database        bdb<br />
suffix          &#8220;dc=iptables,dc=gen,dc=tr&#8221;<br />
rootdn          &#8220;cn=Manager,dc=iptables,dc=gen,dc=tr&#8221;<br />
rootpw          iptables123</strong></td>
</tr>
</tbody>
</table>
<p>Start LDAP server:</p>
<table style="background-color: #ffe4b5; width: 453px; height: 24px;" border="0">
<tbody>
<tr>
<td><strong>[root@rh54srv1]# /etc/init.d/ldap start</strong></td>
</tr>
</tbody>
</table>
<p>Send a sample query to our fresh LDAP server to test the queries. Be careful command should be in single line and shouldn&#8217;t be wrapped, if so, use backslash.</p>
<table style="background-color: #ffe4b5; width: 877px; height: 253px;" border="0">
<tbody>
<tr>
<td>[root@rh54srv1 /]# <strong>ldapsearch -h rh54srv1.iptables.gen.tr -x -D &#8220;cn=Manager,dc=iptables,dc=gen,dc=tr&#8221; -b \  &#8220;dc=iptables,dc=gen,dc=tr&#8221;  -w iptables123</strong><br />
# extended LDIF<br />
#<br />
# LDAPv3<br />
# base &lt;dc=iptables,dc=gen,dc=tr&gt; with scope subtree<br />
# filter: (objectclass=*)<br />
# requesting: ALL<br />
#</p>
<p># search result<br />
search: 2<br />
result: 32 No such object</p>
<p># numResponses: 1</td>
</tr>
</tbody>
</table>
<p>This is a good answer:) though we haven&#8217;t received any records as we don&#8217;t have any.</p>
<p>Now we will migrate our current password and group files into LDAP. Get the following scripts for this purpose:</p>
<p><span id="more-45"></span></p>
<table style="background-color: #ffe4b5; width: 546px; height: 24px;" border="0">
<tbody>
<tr>
<td>[root@rh54srv1 /]# <strong>cd /usr/local</strong><br />
[root@rh54srv1 local]# <strong>wget http://www.padl.com/download/MigrationTools.tgz</strong><br />
[root@rh54srv1 local]# <strong>tar -zxf MigrationTools.tgz</strong><strong><br />
</strong></td>
</tr>
</tbody>
</table>
<p>Edit the file MigrationTools-47/migrate_common.ph under /usr/local folder and adjust the DEFAULT_BASE variable according to your configuration.</p>
<table style="background-color: #ffe4b5; width: 560px; height: 24px;" border="0">
<tbody>
<tr>
<td># Default base<br />
$DEFAULT_BASE = &#8220;dc=iptables,dc=gen,dc=tr&#8221;;</td>
</tr>
</tbody>
</table>
<p>We have the migration tools. Now we can migrate the files into LDAP database:</p>
<table style="background-color: #ffe4b5; width: 589px; height: 80px;" border="0">
<tbody>
<tr>
<td>[root@rh54srv1 local]# <strong>cd MigrationTools-47/</strong><br />
[root@rh54srv1 MigrationTools-47]# <strong>./migrate_base.pl &gt; base.ldif</strong><br />
[root@rh54srv1 MigrationTools-47]# <strong>./migrate_hosts.pl /etc/hosts &gt; hosts.ldif</strong><br />
[root@rh54srv1 MigrationTools-47]# <strong>./migrate_passwd.pl /etc/passwd &gt; passwd.ldif</strong><br />
[root@rh54srv1 MigrationTools-47]# <strong>./migrate_group.pl /etc/group &gt; group.ldif</strong></td>
</tr>
</tbody>
</table>
<p><span style="color: #ff0000;"><strong>NOTICE: </strong></span>Before going further, I need to raise one point. Migration tool generated my base as <strong>&#8220;dc=gen,dc=tr&#8221;</strong> instead of &#8220;dc=iptables,dc=gen,dc=tr&#8221; and created the file base.ldif as such. That is why I needed to remove the heading line below from my base.ldif file in order to add it into LDAP.</p>
<p><strong>The following heading lines were removed from the file.</strong></p>
<table style="background-color: #ffe4b5; width: 550px; height: 24px;" border="0">
<tbody>
<tr>
<td>dn: dc=gen,dc=tr<br />
dc: gen<br />
objectClass: top<br />
objectClass: domain</td>
</tr>
</tbody>
</table>
<p><strong>Time to add ldif files into LDAP database:</strong></p>
<table style="background-color: #ffe4b5; width: 906px; height: 38px;" border="0">
<tbody>
<tr>
<td>[root@rh54srv1 MigrationTools-47]# ldapadd -h rh54srv1.iptables.gen.tr -x -D &#8220;cn=Manager,dc=iptables,dc=gen,dc=tr&#8221; -w iptables123 -f base.ldif</p>
<p>[root@rh54srv1 MigrationTools-47]# ldapadd -h rh54srv1.iptables.gen.tr -x -D &#8220;cn=Manager,dc=iptables,dc=gen,dc=tr&#8221; -w iptables123 -f hosts.ldif</p>
<p>[root@rh54srv1 MigrationTools-47]# ldapadd -h rh54srv1.iptables.gen.tr -x -D &#8220;cn=Manager,dc=iptables,dc=gen,dc=tr&#8221; -w iptables123 -f passwd.ldif</p>
<p>[root@rh54srv1 MigrationTools-47]# ldapadd -h rh54srv1.iptables.gen.tr -x -D &#8220;cn=Manager,dc=iptables,dc=gen,dc=tr&#8221; -w iptables123 -f group.ldif</td>
</tr>
</tbody>
</table>
<p>After these commands, all your user information is transferred into LDAP server database.</p>
<p><strong>[CLIENT CONFIGURATION]</strong></p>
<p>As we have finished server side configuration, now we will setup our client so that all user authentication requests will be sent to our LDAP server. Again our handy tool authconfig does most of the dirty part for us. One command enables ldap authentication.</p>
<table style="background-color: #ffe4b5; width: 886px; height: 38px;" border="0">
<tbody>
<tr>
<td>[root@rh54-2 ~]# <strong>authconfig &#8211;enableldap &#8211;enableldapauth &#8211;ldapserver 192.168.200.1 &#8211;ldapbasedn &#8220;dc=iptables,dc=gen,dc=tr&#8221; &#8211;update</strong></td>
</tr>
</tbody>
</table>
<p>From this moment on, if you ssh into this client machine (rh54-2), you will be authenticated from LDAP server on rh54srv1 instead of /etc/passwd.  All your passwords in /etc/passwd file now are in LDAP. One more thing to do is to add a new username into LDAP to test authentication.</p>
<p><strong>Create an LDIF file adduser.ldif with the following content:</strong></p>
<table style="background-color: #ffe4b5; width: 613px; height: 235px;" border="0">
<tbody>
<tr>
<td>dn: uid=<strong>ldapuser1</strong>,ou=People,dc=iptables,dc=gen,dc=tr<br />
uid: <strong>ldapuser1</strong><br />
cn: <strong>ldapuser1</strong><br />
objectClass: account<br />
objectClass: posixAccount<br />
objectClass: top<br />
objectClass: shadowAccount<br />
userPassword: {crypt}<span style="color: #ff0000;"><strong>myB.IL9LzBxE6</strong></span><br />
shadowLastChange: 14612<br />
shadowMax: 99999<br />
shadowWarning: 7<br />
loginShell: /bin/bash<br />
uidNumber: 2000<br />
gidNumber: 2000<br />
homeDirectory: <strong>/home/ldapuser1</strong></td>
</tr>
</tbody>
</table>
<p>I have already coloured the sections in this sample which needs to be changed. Password can be created with any crypt utility. For example, I have created this crypted password with the following perl command;</p>
<table style="background-color: #ffe4b5; width: 609px; height: 24px;" border="0">
<tbody>
<tr>
<td>#<strong>perl -e &#8220;print crypt(&#8220;<span style="color: #008000;"><strong>testpass</strong></span>&#8220;,&#8221;mysalt&#8221;)&#8221; ; echo </strong><br />
<span style="color: #ff0000;"><strong>myB.IL9LzBxE6</strong></span></td>
</tr>
</tbody>
</table>
<p>Now you can add this new entry into ldap ;</p>
<table style="background-color: #ffe4b5; width: 778px; height: 38px;" border="0">
<tbody>
<tr>
<td>[root@rh54srv1 ~]# <strong>ldapadd -h rh54srv1.iptables.gen.tr -x -D &#8220;cn=Manager,dc=iptables,dc=gen,dc=tr&#8221; -w iptables123 -f adduser.ldif </strong></td>
</tr>
</tbody>
</table>
<p>Best test is by trying to login to client via SSH</p>
<table style="background-color: #ffe4b5; width: 619px; height: 24px;" border="0">
<tbody>
<tr>
<td>[root@rh54srv1 ~]# ssh ldapuser1@192.168.200.81<br />
ldapuser1@192.168.200.81&#8217;s password:<br />
Last login: Sun Jan  3 08:56:43 2010 from rh54srv1.iptables.gen.tr<br />
-bash-3.2$</td>
</tr>
</tbody>
</table>
<p>As you can see authentication is successful. (Note: You may have a different output &#8220;like home directory not found&#8221;. It is because there is no /home/ldapuser1 folder in the client system.</p>
<p>If you want to test ldap manually in the client machine (rh54-2) run the following. The output will be all the password entries in the LDAP server.</p>
<table style="background-color: #ffe4b5; width: 506px; height: 24px;" border="0">
<tbody>
<tr>
<td>[root@rh54-2 ~]# <strong>getent passwd</strong></td>
</tr>
</tbody>
</table>
<p>Now your authentication should be working. I would like to mention about a few points before finishing this article;</p>
<ul>
<li>You should also run authconfig command you run in client in the server. Otherwise authentication utilities will not be aware of LDAP configuration.</li>
<li>As your users are now centrally managed, your home directories should be central as well. In order to configure automatically mounted user home directories, you can have a look at my previous <a href="http://iptables.gen.tr/2010/01/nis-server-and-client-configuration/" target="_blank">article</a> about autofs with NIS authentication.</li>
<li>Always create backup and be careful as authconfig may cause your system inaccessible if not properly managed.</li>
</ul>
<p>Please share your opinions or if you see any mistake in the document let me know.</p>
]]></content:encoded>
			<wfw:commentRss>http://iptables.gen.tr/2010/01/ldap-authentication-howto/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
