<?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>bits &#124; andy smith&#039;s blog &#187; UNIX</title>
	<atom:link href="http://andys.org.uk/bits/tag/unix/feed/" rel="self" type="application/rss+xml" />
	<link>http://andys.org.uk/bits</link>
	<description>random stuff from the mind of a twenty-something professional geek</description>
	<lastBuildDate>Mon, 16 Apr 2012 00:39:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Authenticating Active Directory users on Linux with Likewise Open</title>
		<link>http://andys.org.uk/bits/2010/01/28/likewise-open-and-linux/</link>
		<comments>http://andys.org.uk/bits/2010/01/28/likewise-open-and-linux/#comments</comments>
		<pubDate>Thu, 28 Jan 2010 01:09:35 +0000</pubDate>
		<dc:creator>Andy Smith</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[UNIX]]></category>
		<category><![CDATA[active directory]]></category>
		<category><![CDATA[ad]]></category>
		<category><![CDATA[authentication]]></category>
		<category><![CDATA[likewise]]></category>
		<category><![CDATA[likewise open]]></category>

		<guid isPermaLink="false">http://andys.org.uk/bits/?p=20</guid>
		<description><![CDATA[Historically, if you wanted to use Active Directory to authenticate users on a UNIX box, you were pretty much limited to using LDAP. This works fine for some people, but it&#8217;s not particularly elegant &#8211; especially if you&#8217;re having to create users home directories all the time, which negates some of the point of centralising [...]]]></description>
			<content:encoded><![CDATA[<p>Historically, if you wanted to use Active Directory to authenticate users on a UNIX box, you were pretty much limited to using <a href="http://www.openldap.org/lists/openldap-software/200010/msg00097.html">LDAP</a>. This works fine for some people, but it&#8217;s not particularly elegant &#8211; especially if you&#8217;re having to create users home directories all the time, which negates some of the point of centralising authentication to begin with.</p>
<p>I&#8217;m from a UNIX (mostly Linux) background, so I&#8217;m more at home using UNIX-alike platforms. That said, there&#8217;s a few things that Microsoft do that are particularly useful, and in my opinion AD is one of them (quiet at the back, there). Handily, there&#8217;s a project that can marry the two, and it goes by the name of <a href="http://www.likewise.com/">Likewise</a>.</p>
<p><span id="more-20"></span><a href="http://www.likewise.com/products/likewise_enterprise/index.php">Likewise Enterprise</a> is Likewise Software&#8217;s commercial offering, but they also provide an open-source edition in the form of <a href="http://www.likewise.com/products/likewise_open/index.php">Likewise Open</a>, which is what I&#8217;m going to focus on here. Conceptually, using Likewise is equivalent to binding a Windows machine to a domain, and the method of doing it is similar. The code is somewhat related to <a href="http://www.samba.org">Samba</a>, so some parts of it may be familiar to anyone who&#8217;s meddled around with Samba in any depth.</p>
<h3>Starting out</h3>
<p>First off, you&#8217;ll need the Likewise Open installer, which you can get from here (<a href="http://www.likewise.com/download/index.php">signup required</a>). Grab the installer for your particular distro or operating system &#8211; for this example I&#8217;m using a fresh Debian (lenny) GNU/Linux install, but the process is essentially the same for others, such as Solaris. One you&#8217;ve got it, installing it is just a matter of running it:-</p>
<blockquote>
<pre>adtest:~# <span style="color: #008000;"><strong>chmod +x ./LikewiseIdentityServiceOpen-...-linux-i386-deb-installer</strong></span>
adtest:~# <span style="color: #008000;"><strong>./LikewiseIdentityServiceOpen-...-linux-i386-deb-installer</strong></span></pre>
</blockquote>
<p>Follow the prompts, and after a few seconds you&#8217;ll be returned to a prompt. Assuming the install completed successfully, in the case of Debian (or Ubuntu), running &#8216;<em>dpkg -l | grep likewise</em>&#8216; will show a few new packages have been installed (for RedHat/CentOS, replace &#8216;<em>dpkg -l</em>&#8216; with &#8216;<em>rpm -qa</em>&#8216;).</p>
<p>Before going any further, make sure your resolvers are set up correctly, and that the local machine&#8217;s time is synchronised &#8211; either against an external NTP source, or one of the domain controllers. You can check that DNS resolution is working correctly by running:-</p>
<blockquote>
<pre>adtest:~# <span style="color: #008000;"><strong>host test.example.com</strong></span></pre>
</blockquote>
<p>&#8230;and all being well, you&#8217;ll see something like this:-</p>
<blockquote>
<pre>test.example.com          A     10.1.1.1
test.example.com          A     10.1.2.1</pre>
</blockquote>
<p>If you&#8217;re okay so far, configuring the machine to use AD requires one command:-</p>
<blockquote>
<pre>adtest:~# <span style="color: #008000;"><strong>/opt/likewise/bin/domainjoin-cli join test.example.com andys</strong></span></pre>
</blockquote>
<p>After a few seconds, providing the local machine can see the domain controllers, you should be prompted for your domain password. As when binding a Windows machine to a domain, the account you use must have the right privileges, which usually means that it&#8217;s in the Domain Admins group or similar. So:-</p>
<blockquote>
<pre>Joining to AD Domain:   test.example.com
With Computer DNS Name: adtest.test.example.com

andys@TEST.EXAMPLE.COM's password: <span style="color: #008000;"><strong><em>&lt;domain password&gt;</em></strong></span></pre>
</blockquote>
<p>&#8230;wait a few seconds&#8230;</p>
<blockquote>
<pre>Warning: System restart required
Your system has been configured to authenticate to Active Directory
for the first time. It is recommended that you restart your system
to ensure that all applications recognize the new settings.

SUCCESS</pre>
</blockquote>
<p>Now, in my experience you don&#8217;t strictly need to reboot, however it&#8217;s a good idea to, so go ahead and reboot the machine.</p>
<h3>The basics</h3>
<p>Assuming the box rebooted, we can now test that AD integration is working. Log in, and at a prompt type:-</p>
<blockquote>
<pre>adtest:~# <span style="color: #008000;"><strong>id TEST\\andys</strong></span></pre>
</blockquote>
<p>&#8230;replacing &#8216;<em>TEST\\andys</em>&#8216; with your domain and username. The double backslash is important, because most UNIX shells use &#8216;\&#8217; for escaping characters. If you want, you can also use the &#8216;<em>user@domain</em>&#8216; syntax. If all is well, you&#8217;ll see something like this:-</p>
<blockquote>
<pre>uid=2096628820(TEST\andys) gid=2096628225(TEST\domain^users)
groups=2096628225(TEST\domain^users),2096628224(TEST\domain^admins)</pre>
</blockquote>
<p>At this point I should offer a word of caution: Because the machine is now bound to the domain, it means users on the domain can log into it. Obviously this is the whole point, but it&#8217;s something to be mindful of, especially if the domain is used by many people.</p>
<p>The UIDs and GIDs may look ridiculously large, but don&#8217;t worry &#8211; UIDs under most UNIXen are 32-bit, so this will be fine. There&#8217;s also a good reason for it &#8211; Likewise guarantees that the IDs will be unique and consistent across all machines bound to the same domain. You&#8217;ll also notice that the user&#8217;s primary group is set to the primary group from AD, which is usually &#8216;<em>Domain Users</em>&#8216;.</p>
<p>The <em>domainjoin-cli</em> command also makes some changes to <strong>/etc/nsswitch.conf</strong> and the PAM configuration. On my example Debian box, having a peek at <strong>/etc/pam.d/common-auth</strong> reveals:-</p>
<blockquote>
<pre>auth    sufficient    /lib/security/pam_lsass.so
auth    required    pam_unix.so nullok_secure try_first_pass</pre>
</blockquote>
<p><strong>pam_lsass.so</strong> is the PAM shared library for the lsass &#8211; or <a href="http://en.wikipedia.org/wiki/Local_Security_Authority_Subsystem_Service">Local Security Authority Subsystem Service</a> &#8211; part of Likewise. The example above is simple enough, and accepts domain users, falling back to standard UNIX users if the given username isn&#8217;t a domain user.</p>
<h3>Making changes</h3>
<p>Likewise installs its configuration files in <strong>/etc/likewise</strong>. The one that&#8217;s probably of most interest is <strong>lsassd.conf</strong>, which controls how the lsass daemon <strong>lsassd</strong> handles users. Before going into any detail, you&#8217;ll notice that lsassd.conf is split into two sections &#8211; the first being for domain users (the <span style="color: #000080;">[auth provider:lsa-activedirectory-provider]</span> section), and the second being for &#8216;local&#8217; users (under <span style="color: #000080;">[auth provider:lsa-local-provider]</span>). The local users are usually just &#8216;<em>COMPUTER\Administrator</em>&#8216; and &#8216;<em>COMPUTER\Guest</em>&#8216; (where <em>COMPUTER</em> is the name of the local machine), and are synonymous to the <em>Administrator</em> and <em>Guest</em> accounts on Windows machines. Chances are you won&#8217;t need to touch the local users section, so we can safely ignore it.</p>
<p>There&#8217;s quite a few options to play with in lssasd.conf, but the main ones we&#8217;re interested in are:-</p>
<ul>
<li><strong>login-shell-template</strong>, which allows us to set the default shell for domain users. This is (by default) set to <strong>/bin/sh</strong>, so in many cases you might want to change it to <strong>/bin/bash</strong>.</li>
<li><strong>homedir-template</strong>, which specifies where domain users&#8217; home directories will be created. The default for this is <strong>%H/local/%D/%U</strong>, which in our example would expand to <strong>/home/local/TEST/andys</strong> for my account. Personally, I prefer to drop the &#8216;local&#8217; bit and use <strong>%H/%D/%U</strong>, which would change my home directory to <strong>/home/TEST/andys</strong>.</li>
<li><strong>require-membership-of</strong>, which lets us specify which groups are allowed to authenticate against this machine in a comma-separated list.</li>
</ul>
<p>It&#8217;s important to note that if you use the last option, <span style="color: #ff0000;"><span style="text-decoration: underline;">any domain user which isn&#8217;t a member of one of the specified groups will fail any PAM configuration that calls pam_lsass.so</span></span>.  This means that if you wanted to allow certains groups SSH access, whilst allowing a larger set of groups access to FTP, you don&#8217;t want to omit the FTP user groups from here. If you&#8217;re building this kind of setup, you&#8217;ll want to allow all the groups in lsassd.conf, and then build your PAM configuration to conditionally allow access based on group membership using <a href="http://www.kernel.org/pub/linux/libs/pam/Linux-PAM-html/sag-pam_group.html">pam_group</a>.</p>
<p>Once you&#8217;ve finished making your configuration changes, you&#8217;ll need to tell Likewise to reload the configuration:-</p>
<blockquote>
<pre>adtest:~# <span style="color: #008000;"><strong>/opt/likewise/bin/lw-refresh-configuration</strong></span>
Configuration successfully loaded from disk.</pre>
</blockquote>
<p>It also doesn&#8217;t hurt (and I&#8217;ve sometimes found it neccessary) to clear the local AD cache:-</p>
<blockquote>
<pre>adtest:~# <span style="color: #008000;"><strong>/opt/likewise/bin/lw-ad-cache --delete-all</strong></span>
The cache has been emptied successfully.</pre>
</blockquote>
<p>&#8230;and that&#8217;s it! You should now have AD authentication working through PAM.</p>
<h3>Useful commands</h3>
<p>Likewise installs quite a few tools in <strong>/opt/likewise/bin</strong> (many of which are symlinks to <strong>lw-lsa</strong>), some of which come in handy for testing:-</p>
<ul>
<li><strong>lw-refresh-configuration</strong>, which as mentioned above reloads the <strong>lsassd</strong> configuration from <strong>lsassd.conf</strong>.</li>
<li><strong>lw-ad-cache</strong> (also partly mentioned above), which lets us manipulate the local AD cache. For example, <strong>lw-ad-cache &#8211;enum-users</strong> will list the users&#8217; details currently stored in the cache.</li>
<li><strong>lw-enum-users</strong>/<strong>lw-enum-groups</strong>, which predictably list all the users and groups in the domain.</li>
<li><strong>lw-get-status</strong>, which shows quite a bit of information about the domain itself.</li>
</ul>
<p>These are just a few, so it&#8217;s useful to have a poke about in <strong>/opt/likewise/bin</strong> and see what there is.</p>
<h3>Hints</h3>
<p>Because Likewise integrates itself via PAM, pretty much everything which can work with normal UNIX users can cope fine with domain users. For instance:-</p>
<ul>
<li>You can use the tilde (~) shortcut to go to a domain user&#8217;s home directory, for example <strong>cd ~andys@TEST</strong>. For some reason, the backslash notation doesn&#8217;t work here, and you may also notice that tab completion doesn&#8217;t work either.</li>
<li>With most things, you can refer to domain users as either <em>TEST\\andys</em>, <em>TEST.EXAMPLE.COM\\andys</em>, <em>andys@TEST</em> or <em>andys@TEST.EXAMPLE.COM</em>, including when logging in on the console or via SSH. There are exceptions (such as the previous point), but they&#8217;re few and far between.</li>
<li>Sudo happily works with domain groups &#8211; just remember to double-backslash.</li>
<li>You can use <strong>chown</strong> and <strong>chgrp</strong> in the ways you&#8217;d normally expect, using either the domain group names, or their GIDs.</li>
<li><strong><a href="http://www.suse.de/~agruen/acl/linux-acls/online/">ACLs</a></strong> (under Linux) also work, so if you&#8217;ve mounted a partition with the &#8216;<strong>acl</strong>&#8216; option, you can use <strong>setfacl</strong> as normal.</li>
</ul>
<h3>If it all goes wrong&#8230;</h3>
<p>Sometimes things go wrong. With Likewise, it&#8217;s usually straightforward. If you&#8217;re getting errors when binding to the domain with <strong>domainjoin-cli</strong>, it&#8217;s usually because it&#8217;s having problems connecting to the domain controller. If your domain controllers are on a different network, check that any firewalls inbetween aren&#8217;t dropping SMB traffic. The <strong>domainjoin-cli</strong> command should give you a definitive list of ports it needs open to communicate with the domain controller.</p>
<p>Once up and running, I&#8217;ve found Likewise Open to be very stable, but on the odd occasion that something has gone awry, it&#8217;s often enough to just restart the <strong>lsassd</strong> daemon. Failing that, try emptying the cache (with <strong>lw-ad-cache &#8211;delete-all</strong>). If you&#8217;re still getting odd errors, it might be worth checking out the <a href="http://www.likewise.com/resources/documentation_library/">documentation</a> or the <a href="http://www.likewise.com/community/index.php/forums/">forums</a>.</p>
<h3>Where to from here?</h3>
<p>Because the PAM magic happens with pam_lsass, in theory anything which uses PAM can be made AD-aware. I&#8217;ve personally used it with <a href="http://www.pureftpd.org">Pure-FTPd</a> to provide company-wide access to an fileserver, and it works flawlessly with <strong>gdm</strong>, so you can use it on your desktop. Again, because it&#8217;s PAM-based, it can be stacked with other modules such as <strong>pam_securid</strong> (for RSA&#8217;s SecurID tokens) or <a href="http://www.gsp.com/cgi-bin/man.cgi?section=8&amp;topic=pam_opie">pam_opie</a> (for one-time password sets).</p>
<p>Ironically, one thing that does require a little bit more configuration is Samba &#8211; something I&#8217;ll cover in a future post.</p>
<p><strong>Update</strong>: Yvo van Doorn <a href="http://andys.org.uk/bits/2010/01/28/likewise-open-and-linux/comment-page-1/#comment-30">comments below</a> with a handy hint if you only need access to one domain, which should save on keyboard wear for some users <img src='http://andys.org.uk/bits/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://andys.org.uk/bits/2010/01/28/likewise-open-and-linux/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
	</channel>
</rss>

