<?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>hostatic.ro &#187; How-To</title>
	<atom:link href="http://www.hostatic.ro/category/how-to/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.hostatic.ro</link>
	<description></description>
	<lastBuildDate>Thu, 29 Sep 2011 21:45:31 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.1</generator>
		<item>
		<title>Using the Magic SysRq keys</title>
		<link>http://www.hostatic.ro/2011/07/13/using-the-magic-sysrq-keys/</link>
		<comments>http://www.hostatic.ro/2011/07/13/using-the-magic-sysrq-keys/#comments</comments>
		<pubDate>Wed, 13 Jul 2011 19:42:52 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
				<category><![CDATA[How-To]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[key]]></category>
		<category><![CDATA[magic]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[sysrq]]></category>

		<guid isPermaLink="false">http://www.hostatic.ro/?p=102</guid>
		<description><![CDATA[One of the less known functionalities implemented in the Linux kernel is the Magic SysRq key. Initially implemented as a debugging feature for kernel development it has also made its way into system administration use and the /proc filesystem. Basically the Magic SysRq keys are low level commands that can be sent to the kernel [...]]]></description>
			<content:encoded><![CDATA[<p>One of the less known functionalities implemented in the Linux kernel is the Magic SysRq key. Initially implemented as a debugging feature for kernel development it has also made its way into system administration use and the /proc filesystem.</p>
<p>Basically the Magic SysRq keys are low level commands that can be sent to the kernel regardless of a system&#8217;s state. That being said it can be most useful in extreme cases where the system is not responding to do a reboot, unmount partitions or sync the partitions (flush their write buffer to disk).</p>
<p>Before being able to actually use this, you have to enable the SysRq keys:</p>
<ul>
echo &#8220;1&#8243; > /proc/sys/kernel/sysrq
</ul>
<p>All these commands can be sent to the kernel using the combination:</p>
<ul>
Alt+SysRQ+[key]
</ul>
<p>or by piping the key to the /proc filesystem:</p>
<ul>
echo [key] > /proc/sysrq-trigger
</ul>
<p>The SysRQ key on the keyboard can usually be found on the same key as &#8220;PrintScreen&#8221;.<br />
A full list of the commands that can be sent can be found on <a href="http://en.wikipedia.org/wiki/Magic_SysRq_key">Wikipedia</a>.</p>
<p>Now you ask yourself, when would I use this? Let&#8217;s take the most common example: a server that has become completely unresponsive and the only solution would be to reboot it. But that server hosts a database with precious information and you do not know if all the information kept in memory by the database has been written to disk or if the sudden reboot would trigger errors and inconsistencies on the filesystem. The Magic SysRQ keys would come in handy now:</p>
<p>- gracefully terminate all running processes except init (PID1):</p>
<ul>
Alt+SysRq+e
</ul>
<p>or</p>
<ul>
echo &#8220;e&#8221; > /proc/sysrq-trigger
</ul>
<p>- kill all the stubborn processes:</p>
<ul>
Alt+SysRq+k
</ul>
<p>or</p>
<ul>
echo &#8220;k&#8221; > /proc/sysrq-trigger
</ul>
<p>- sync all mounted filesystems &#8211; meaning flush all the memory buffers to disk:</p>
<ul>
Alt+SysRq+s
</ul>
<p>or</p>
<ul>
echo &#8220;s&#8221; > /proc/sysrq-trigger
</ul>
<p>- re-mount all partitions as read-only:</p>
<ul>
Alt+SysRq+u
</ul>
<p>or</p>
<ul>
echo &#8220;u&#8221; > /proc/sysrq-trigger
</ul>
<p>- finally tell the box to immediately reboot:</p>
<ul>
Alt+SysRq+b
</ul>
<p>or</p>
<ul>
echo &#8220;b&#8221; > /proc/sysrq-trigger
</ul>
<p>The case above is the most common one, but there are other times on the SysRq keys might come in handy. Let&#8217;s say you have accidentally deleted something from an ext2/3/4 partition. We know that on those filesystems the data isn&#8217;t immediately removed from the drive, but marked as deleted and will be overwritten the next time a process tries to write somewhere on the disk. Before you can use tools to un-delete &#8211; we will cover that in the next episode &#8211; we can tell the kernel to force re-mount all partitions as read-only, including the / partition:</p>
<ul>
Alt+SysRq+u
</ul>
<p>or</p>
<ul>
echo &#8220;u&#8221; > /proc/sysrq-trigger
</ul>
<p>Now we can be sure that no process will overwrite our precious data and use some tool to recover the metadata.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hostatic.ro/2011/07/13/using-the-magic-sysrq-keys/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Apt Pinning in Debian</title>
		<link>http://www.hostatic.ro/2009/11/25/apt-pinning-in-debian/</link>
		<comments>http://www.hostatic.ro/2009/11/25/apt-pinning-in-debian/#comments</comments>
		<pubDate>Wed, 25 Nov 2009 16:47:27 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
				<category><![CDATA[How-To]]></category>
		<category><![CDATA[apt]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[packages]]></category>
		<category><![CDATA[pin]]></category>
		<category><![CDATA[repository]]></category>

		<guid isPermaLink="false">http://www.hostatic.ro/?p=55</guid>
		<description><![CDATA[Ever wanted to run certain packages from one version of the operating system ( in this case Debian ) without having to upgrade (or downgrade) the entire system ? Well, the &#8220;Pin&#8221; option in the Apt package management system lets you do that. It&#8217;s pretty simple too! 1. Add the repositories for the two versions [...]]]></description>
			<content:encoded><![CDATA[<p>Ever wanted to run certain packages from one version of the operating system ( in this case Debian ) without having to upgrade (or downgrade) the entire system ? </p>
<p>Well, the &#8220;Pin&#8221; option in the Apt package management system lets you do that. It&#8217;s pretty simple too!</p>
<p>1. Add the repositories for the two versions you want to have packages from in <strong>  /etc/apt/sources.list </strong>. In this example we have Debian Stable and Testing:</p>
<blockquote>
<ol>
<strong><br />
#Stable<br />
deb http://ftp.us.debian.org/debian stable main non-free contrib<br />
deb http://non-us.debian.org/debian-non-US stable/non-US main contrib non-free</p>
<p>#Testing<br />
deb http://ftp.us.debian.org/debian testing main non-free contrib<br />
deb http://non-us.debian.org/debian-non-US testing/non-US main contrib non-free<br />
</strong>
</ol>
</blockquote>
<p>Run <strong>apt-get update</strong> to add the repositories to apt.</p>
<p>2. Next, modify the file <strong>/etc/apt/preferences</strong>. This is where the actual &#8220;pinning&#8221; takes place. By default, apt installs the highest version available. So let&#8217;s say we would have the two repositories and we would like to install the package &#8220;dovecot-common&#8221;. Apt will take the highest version of that package which is naturally available in the &#8220;Testing&#8221; repository. But say we wanted to run the older of version of &#8220;dovecot-common&#8221; (for our own reasons, doesn&#8217;t matter why), which is available in the &#8220;Stable&#8221; repository. We would have this in our <strong>/etc/apt/preferences</strong> file:</p>
<blockquote>
<ol>
<strong><br />
Package: dovecot-common<br />
Pin: release a=stable<br />
Pin-Priority: 700</p>
<p>Package: dovecot-common<br />
Pin: release a=testing<br />
Pin-Priority: 600<br />
</strong>
</p></blockquote>
</ol>
<p>Notice that we have a higher priority number for &#8220;dovecot-common&#8221; in the &#8220;stable&#8221; release. In Apt, the package with the highest priority wins, no matter the package version.</p>
<p>So now that you know this, you can use it to mix-match between packages from different repositories, while using strictly apt, no forcing of install and keeping them updated (if a newer version appears in that repository, apt will install it).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hostatic.ro/2009/11/25/apt-pinning-in-debian/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dovecot 1.2 with quotas and quota warnings</title>
		<link>http://www.hostatic.ro/2009/11/11/dovecot-1-2-with-quotas-and-quota-warnings/</link>
		<comments>http://www.hostatic.ro/2009/11/11/dovecot-1-2-with-quotas-and-quota-warnings/#comments</comments>
		<pubDate>Wed, 11 Nov 2009 13:28:16 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
				<category><![CDATA[How-To]]></category>
		<category><![CDATA[dovecot]]></category>
		<category><![CDATA[ldap]]></category>
		<category><![CDATA[quota]]></category>
		<category><![CDATA[quota warnings]]></category>
		<category><![CDATA[user]]></category>
		<category><![CDATA[warning]]></category>

		<guid isPermaLink="false">http://www.hostatic.ro/?p=51</guid>
		<description><![CDATA[We have recently upgraded our mail servers running Debian Etch to Lenny and noticing that Dovecot 1.2 has been backported to Lenny backports, we decided to upgrade to Dovecot to take advantage of its fixes, improved security and quota settings. Setting up quotas and warnings for any Dovecot above 1.0 is very simple. 1) First [...]]]></description>
			<content:encoded><![CDATA[<p>We have recently upgraded our mail servers running Debian Etch to Lenny and noticing that Dovecot 1.2 has been backported to Lenny backports, we decided to upgrade to Dovecot to take advantage of its fixes, improved security and quota settings. </p>
<p>Setting up quotas and warnings for any Dovecot above 1.0 is very simple.</p>
<p>1) First step is to enable the quota plugin for all protocols enabled in Dovecot ( pop3, imap and lda if you use it). This is done by just adding the line:</p>
<blockquote>
<ol>
<strong> mail_plugins = quota </strong>
</ol>
</blockquote>
<p>and for the IMAP protocol:</p>
<blockquote>
<ol>
<strong> mail_plugins = quota imap_quota </strong>
</ol>
</blockquote>
<p>2) Setup the plugin:</p>
<blockquote>
<ol>
<strong><br />
# Quota plugin settings<br />
plugin {<br />
         quota = maildir:User quota<br />
         #Quota limit is 1GB<br />
         quota_rule = *:storage=1G<br />
         #We add 100Mb more for Trash<br />
         quota_rule2 = Trash:storage=100M<br />
         #We set up warnings at 75% and 90%<br />
         quota_warning = storage=75%% /opt/mail.sh 75 %u<br />
         quota_warning2 = storage=90%% /opt/mail.sh 90 %u<br />
}<br />
</strong>
</ol>
</blockquote>
<p>We can add as many rules and warnings as we want, just by adding and incrementing a number at the end of the warning or rule ( like above: quota_rule, quota_rule2 and so on ).</p>
<p>The first variable, &#8220;quota&#8221;, is the quota root and is a name that is sent to the IMAP client and can be anything you want.</p>
<p>The second variable is the quota itself and you can set it up using several limits: storage,bytes,messages,backend and ignore (this ignores quota for a specific mailbox). All variables support besides numbers the b/k/M/G/T/% suffixes. For example: 100M, 1G, 30% and so on.</p>
<p>The third variable sets up the quota warning. Using the limit you set up above in the rule you set up the warning at what level you want, by using a fixed number or percent. In the above example we used percent. In this case you need the double % ( %% ) so it can be escaped by dovecot. After the warning limit is set, in the same line, separated by space, is the command to run when that limit is reached. In this case it is a custom script that takes two command line arguments: the first one is the percent and the second one is the user that has reached the limit and to which to send the warning. </p>
<p>We set up the second argument (the user) as dovecot&#8217;s %u variable which is set in the ldap configuration, in the filter string. You can make this anything you want, taking the user dynamically through whichever system you have configured as your user database and whichever variable you have set up as you user.</p>
<p>For example, in my dovecot-ldap.conf this is what we have: </p>
<blockquote>
<ol>
<strong> pass_filter = (&#038;(objectClass=person)(userPrincipalName=%u)) </strong>
</ol>
</blockquote>
<p>and this is where I take my %u from.</p>
<p>And finally this is the script I use to send the warning. It uses the default sendmail binary, a simple text file and the two arguments taken from the command line:</p>
<blockquote>
<ol>
<strong><br />
#!/bin/bash</p>
<p>PERCENT=$1<br />
USER=$2</p>
<p>echo &#8220;From: postmaster@domain.org<br />
To: $USER<br />
Subject: Your email quota is $PERCENT% full<br />
Content-Type: text/plain; charset=&#8221;UTF-8&#8243;</p>
<p>This is an automatic message to warn that your  mailbox is now $PERCENT% full.&#8221; > /tmp/quota.email.$USER</p>
<p>cat /tmp/quota.email.$USER | /usr/sbin/sendmail -f postmaster@domain.org $USER</p>
<p>rm /tmp/quota.email.$USER<br />
</strong>
</ol>
</blockquote>
<p>That&#8217;s it! Whenever the user reaches its defined quotas he / she will receive a warning email. This quota are global, any user will have the same quota. If you want per-user quotas and / or soft-quotas check out my later edit below!</p>
<p><strong><br />
LATER EDIT:<br />
</strong></p>
<p>If you want to make your quotas non-enforcing, that means the user will still receive the warnings but if he or she reaches the quota, their e-mails will not be blocked and they will still be able to receive, you must modify your &#8220;quota&#8221; variable in the plugin&#8217;s settings (the quota root). Make your settings look like this:</p>
<blockquote>
<ol>
<strong><br />
# Quota plugin settings<br />
plugin {<br />
         quota = dict:user::noenforcing:file:/opt/data/mailboxes/%u/Maildir/dovecot-quota<br />
         #Quota limit is 1GB<br />
         quota_rule = *:storage=1G<br />
         #We add 100Mb more for Trash<br />
         quota_rule2 = Trash:storage=100M<br />
         #We set up warnings at 75% and 90%<br />
         quota_warning = storage=75%% /opt/mail.sh 75 %u<br />
         quota_warning2 = storage=90%% /opt/mail.sh 90 %u<br />
}<br />
</strong>
</ol>
</blockquote>
<p>Notice the only thing changed is the first variable: &#8220;quota&#8221;.</p>
<p>Also, if you want to use LDAP attributes to change your users&#8217; quotas on a per-user basis, you need to do the following:</p>
<p>1) Rename your dovecot-ldap.conf file to dovecot-passdb-ldap.conf :</p>
<p><strong></p>
<ol>
<blockquote><p>
mv /etc/dovecot/dovecot-ldap.conf /etc/dovecot/dovecot-passdb-ldap.conf<br />
</strong>
</ol>
</blockquote>
<p>2) Create a symlink to dovecot-passdb-ldap.conf called dovecot-userdb-ldap.conf :</p>
<p><strong></p>
<ol>
<blockquote><p>
ln -s /etc/dovecot/dovecot-passdb-ldap.conf /etc/dovecot/dovecot-userdb-ldap.conf<br />
</strong>
</ol>
</blockquote>
<p>3) Modify your dovecot.conf file to point to these files as DBs for users and passwords:</p>
<p><strong></p>
<ol>
<blockquote><p>
passdb ldap {<br />
        args = /etc/dovecot/dovecot-passdb-ldap.conf<br />
}<br />
userdb ldap {<br />
        args = /etc/dovecot/dovecot-userdb-ldap.conf<br />
}<br />
</strong>
</ol>
</blockquote>
<p>4) And finally make sure your &#8221; /etc/dovecot/dovecot-passdb-ldap.conf &#8221; file looks like this:</p>
<p><strong></p>
<ol>
<blockquote><p>
hosts = <your-ldap-server><br />
dn = <your_authorized_user_canonical_name><br />
dnpass =
<the_password_for_the_authorized_user>
auth_bind = yes<br />
ldap_version = 3<br />
base = dc=example, dc=org<br />
pass_filter = (&#038;(objectClass=person)(userPrincipalName=%u))<br />
user_filter = (&#038;(objectClass=person)(userPrincipalName=%u))<br />
user_attrs = otherPager=quota_rule=*:bytes=%$, userPrincipalName=home=/opt/data/mailboxes/%u<br />
</strong>
</ol>
</blockquote>
<p>Notice we use the &#8221; userPrincipalName &#8221; as the attribute for username in dovecot (the username the users will also use to authenticate to dovecot). If you want, you can change this to whatever you want, like sAMAccountName.</p>
<p>Also, if  you look carefully, notice that we used the &#8221; otherPager &#8221; attribute from LDAP as the attribute for user quota. We just modify this attribute for whatever we want to override the default quota for a certain user. For example we want to modify for user jon.doe, we just put in that attribute: &#8221; 2G &#8221; and the user will have 2 gigabytes. You can use any existing attribute that is not used and will not be or you can add your own to all the users in the LDAP tree.</p>
<p>That&#8217;s it! Restart Dovecot and it should work!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hostatic.ro/2009/11/11/dovecot-1-2-with-quotas-and-quota-warnings/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Debian, Openvz and Broadcom 5716 ethernet cards</title>
		<link>http://www.hostatic.ro/2009/09/21/debian-openvz-and-broadcom-5716-ethernet-cards/</link>
		<comments>http://www.hostatic.ro/2009/09/21/debian-openvz-and-broadcom-5716-ethernet-cards/#comments</comments>
		<pubDate>Mon, 21 Sep 2009 14:31:15 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
				<category><![CDATA[How-To]]></category>
		<category><![CDATA[broadcom]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[drivers]]></category>
		<category><![CDATA[kernel]]></category>
		<category><![CDATA[openvz]]></category>

		<guid isPermaLink="false">http://www.hostatic.ro/?p=23</guid>
		<description><![CDATA[Recently we have bought a new server to replace an old HP DL360 that failed. The decision was made to buy a new Dell R410. This server, like many Dell servers, comes with a Broadcom dual-port Ethernet card. We wanted to install Debian Lenny (5.0) on it and this should have worked just fine with [...]]]></description>
			<content:encoded><![CDATA[<p>Recently we have bought a new server to replace an old HP DL360 that failed. The decision was made to buy a new Dell R410. This server, like many Dell servers, comes with a Broadcom dual-port Ethernet card. We wanted to install Debian Lenny (5.0) on it and this should have worked just fine with the bnx2 drivers that come with the latest Debian. But this particular ethernet card, Broadcom 5716, doesn&#8217;t work with them!</p>
<p>So we had to get the latest drivers for it! But because Broadcom doesn&#8217;t play nice with open-source, you have to get their latest drivers in binary form or compile them yourself from source. Because the compiling using their tarball failed for unknown reason and I didn&#8217;t have time to debug it, I searched for a precompiled Debian package (.deb). And it seems the deb from Debian&#8217;s Squeeze repository has the drivers that work with this particular card. So I downloaded and installed the package:</p>
<blockquote>
<ol>
wget http://ftp.ro.debian.org/debian/pool/non-free/f/firmware-nonfree/firmware-bnx2_0.18_all.deb</p>
<p>dpkg -i firmware-bnx2_0.18_all.deb
</ol>
</blockquote>
<p>Rebooted the machine but still no ethernet drivers. More searching lead me to find out that this firmware works with Linux kernel 2.6.30.  Upgraded to this kernel (using debs also), rebooted and &#8230; network connectivity! But my joy quickly ended when I noticed on Openvz&#8217;s wiki that they only offer Openvz patches up to 2.6.27! So I had network but no way to use virtual machines with Openvz on it. (and this is what we use in our shop so no other options&#8230;).</p>
<p>But with Google&#8217;s help again, I noticed that Broadcom 5716 is supported in 2.6.27! No pre-compiled deb packages for this version, but no problem, we can compile our own. These are the steps to compile 2.6.27 with Openvz support and install the Broadcom latest drivers and make them work:</p>
<blockquote>
<ol>
cd /usr/src</p>
<p>wget http://kernel.org/pub/linux/kernel/v2.6/linux-2.6.27.tar.bz2</p>
<p>tar xjf linux-2.6.27.tar.bz2</p>
<p>cd linux-2.6.27</p>
<p>wget http://download.openvz.org/kernel/branches/2.6.27/2.6.27-briullov.1/patches/patch-briullov.1-combined.gz</p>
<p>(or whatever is the latest kernel patch for your kernel)</p>
<p>gunzip patch-briullov.1-combined.gz</p>
<p>wget http://download.openvz.org/kernel/branches/2.6.27/2.6.27-briullov.1/configs/kernel-2.6.27-x86_64.config.ovz</p>
<p>OR</p>
<p>wget http://download.openvz.org/kernel/branches/2.6.27/2.6.27-briullov.1/configs/kernel-2.6.27-i686.config.ovz</p>
<p>(depends on what platform your machine runs 32bit or 64bit)</p>
<p>cp kernel-2.6.27-*.config.ovz .config</p>
<p>patch -p1 &lt; patch-briullov.1-combined</p>
<p>make oldconfig</p>
<p>make</p>
<p>make modules_install</p>
<p>make install</p>
<p>cd /boot</p>
<p>mkinitramfs -o initrd.img-2.6.27.21</p>
<p>update-grub</p>
<p>Edit /boot/grub/menu.lst and make the kernel 2.6.27.21 the default one.</p>
<p>wget http://ftp.ro.debian.org/debian/pool/non-free/f/firmware-nonfree/firmware-bnx2_0.18_all.deb</p>
<p>dpkg -i firmware-bnx2_0.18_all.deb</p>
<p>( in case you didn&#8217;t download and install the firmware earlier )</p>
<p>update-initramfs -u -t -k 2.6.27.21</p>
<p>apt-get install vzctl vzquota rsync</p>
<p>reboot
</ol>
</blockquote>
<p>When you reboot in your system again, networking should work just fine along with Openvz!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hostatic.ro/2009/09/21/debian-openvz-and-broadcom-5716-ethernet-cards/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Configuring a Samba File sharing server with Active Directory authentication</title>
		<link>http://www.hostatic.ro/2009/06/03/configuring-a-samba-file-sharing-server-with-active-directory-authentication/</link>
		<comments>http://www.hostatic.ro/2009/06/03/configuring-a-samba-file-sharing-server-with-active-directory-authentication/#comments</comments>
		<pubDate>Wed, 03 Jun 2009 12:50:47 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
				<category><![CDATA[How-To]]></category>
		<category><![CDATA[active directory]]></category>
		<category><![CDATA[authentication]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[file sharing]]></category>
		<category><![CDATA[ldap]]></category>
		<category><![CDATA[samba]]></category>

		<guid isPermaLink="false">http://www.hostatic.ro/?p=9</guid>
		<description><![CDATA[Configuring a Samba server to use AD (LDAP) authentication can be a little tricky, especially because of the the little PAM tricks you need to do. I have searched a lot for info and tutorials, each giving you a little bit of the picture, and tested them until I came to a solution.  I hope [...]]]></description>
			<content:encoded><![CDATA[<p>Configuring a Samba server to use AD (LDAP) authentication can be a little tricky, especially because of the the little PAM tricks you need to do. I have searched a lot for info and tutorials, each giving you a little bit of the picture, and tested them until I came to a solution.  I hope to spare you some of the work of digging and testing ;) Here goes!</p>
<p>This how-to is tested and works on a Debian system (4.0 / 5.0) using Samba version 3.2.5. It should work on other distros with minimum modifications but I do not guarantee it. Also, this is a copy / paste how-to, although I provided some small explanations at the end. You just need to modify generic info like &#8220;YOUR.DOMAIN&#8221; to your systems specific details.</p>
<p><strong>Installing the packages</strong></p>
<p>First we are going to install the needed packages:</p>
<p style="text-align: left;">&#8221; sudo apt-get install samba samba-common libkrb53 libpam-krb5 krb5-config krb5-user winbind &#8220;</p>
<p style="text-align: left;"><strong>Configuring nsswitch</strong></p>
<p style="text-align: left;">Edit the file <strong>/etc/nsswitch.conf</strong> in order to have the following contents:<strong> </strong></p>
<blockquote>
<p style="text-align: left;"># /etc/nsswitch.conf<br />
#<br />
# Example configuration of GNU Name Service Switch functionality.<br />
# If you have the `glibc-doc-reference&#8217; and `info&#8217; packages installed, try:<br />
# `info libc &#8220;Name Service Switch&#8221;&#8216; for information about this file.</p>
<p># The next 3 lines are modified for winbind password checking before *nix password checking</p>
<p>passwd:         winbind compat<br />
group:          winbind compat<br />
shadow:         winbind compat</p>
<p>hosts:          files dns wins<br />
networks:       files dns</p>
<p>protocols:      db files<br />
services:       db files<br />
ethers:         db files<br />
rpc:            db files</p>
<p>netgroup:       nis<strong><br />
</strong></p></blockquote>
<p style="text-align: left;"><strong>Configuring Kerberos5:</strong></p>
<p style="text-align: left;">Now you need to edit the file <strong>/etc/krb5.conf</strong> to have the following contents:<strong> </strong></p>
<blockquote>
<p style="text-align: left;">[libdefaults]<br />
default_realm =  YOUR.DOMAIN<br />
forwardable = true<br />
ticket_lifetime = 24000<br />
dns_lookup_kdc = false<br />
dns_lookup_realm = false</p>
<p>[realms]<br />
YOUR.DOMAIN = {<br />
kdc =  your.AD.server<br />
admin_server = your.AD.server<br />
default_domain = YOUR.DOMAIN<br />
}</p></blockquote>
<blockquote>
<p style="text-align: left;">[domain_realm]<br />
.your.domain =  YOUR.DOMAIN<br />
your.domain =  YOUR.DOMAIN</p>
<p>[login]<br />
krb4_convert = true<br />
krb4_get_tickets = false</p>
<p>[logging]<br />
default = FILE:/var/log/krb5libs.log<br />
kdc = FILE:/var/log/krb5kdc.log<br />
admin_server = FILE:/var/log/kadmind.log</p>
<p>[appdefaults]<br />
pam = {<br />
debug = false<br />
ticket_lifetime = 36000<br />
renew_lifetime = 36000<br />
forwardable = true<br />
krb4_convert = false<br />
}<strong><br />
</strong></p></blockquote>
<p style="text-align: left;"><strong>Configuring PAM</strong></p>
<p style="text-align: left;">The next step is to configure PAM to first try to use Winbind authentication instead of local *nix style authenticaion. This will NOT mess with your local authentication for terminal or SSH access.</p>
<p style="text-align: left;">First file we need to edit is<strong> /etc/pam.d/common-account </strong>:</p>
<blockquote>
<p style="text-align: left;">#<br />
# /etc/pam.d/common-account &#8211; authorization settings common to all services<br />
#<br />
# This file is included from other service-specific PAM config files,<br />
# and should contain a list of the authorization modules that define<br />
# the central access policy for use on the system.  The default is to<br />
# only deny service to users whose accounts are expired in /etc/shadow.<br />
#</p>
<p># PAM Winbind plugin before *nix accounting<br />
account sufficient      pam_winbind.so<br />
account required        pam_unix.so</p></blockquote>
<p style="text-align: left;">
<p style="text-align: left;">Next one is<strong> /etc/pam.d/common-auth</strong> :</p>
<blockquote>
<p style="text-align: left;"># /etc/pam.d/common-auth &#8211; authentication settings common to all services<br />
#<br />
# This file is included from other service-specific PAM config files,<br />
# and should contain a list of the authentication modules that define<br />
# the central authentication scheme for use on the system<br />
# (e.g., /etc/shadow, LDAP, Kerberos, etc.).  The default is to use the<br />
# traditional Unix authentication mechanisms.</p>
<p># PAM winbind plugin before *nix authentication<br />
auth       required     /lib/security/pam_securetty.so<br />
auth       sufficient   /lib/security/pam_winbind.so<br />
auth       sufficient   /lib/security/pam_unix.so use_first_pass<br />
auth       required     /lib/security/pam_nologin.so</p></blockquote>
<p style="text-align: left;">
<p style="text-align: left;">And the last one is <strong>/etc/pam.d/common-password</strong> :</p>
<blockquote>
<p style="text-align: left;"># /etc/pam.d/common-password &#8211; password-related modules common to all services<br />
#<br />
# This file is included from other service-specific PAM config files,<br />
# and should contain a list of modules that define  the services to be<br />
#used to change user passwords.  The default is pam_unix</p>
<p># The &#8220;nullok&#8221; option allows users to change an empty password, else<br />
# empty passwords are treated as locked accounts.<br />
#<br />
# (Add `md5&#8242; after the module name to enable MD5 passwords)<br />
#<br />
# The &#8220;obscure&#8221; option replaces the old `OBSCURE_CHECKS_ENAB&#8217; option in<br />
# login.defs. Also the &#8220;min&#8221; and &#8220;max&#8221; options enforce the length of the<br />
# new password.</p>
<p>password   sufficient pam_winbind.so<br />
password   sufficient pam_unix.so nullok obscure md5</p></blockquote>
<p style="text-align: left;">
<p style="text-align: left;"><strong>Configuring Samba and the shares </strong></p>
<p style="text-align: left;">First create the directories that you will use for the shares. In this example we will use /opt/data/samba in which we will make 2 other directories: public and restricted.</p>
<p style="text-align: left;">Now edit the file<strong> /etc/samba/smb.conf :</strong></p>
<blockquote>
<p style="text-align: left;">[global]<br />
debug level = 3<br />
kernel oplocks = no<br />
realm = YOUR.DOMAIN<br />
workgroup = DOMAIN  ### domain name without the TLD &#8211; .com for example ###<br />
netbios name = &lt;A name by which the server will be seen in the network&gt;<br />
server string =  File Server<br />
load printers = no<br />
log file = /var/log/samba/debug.log<br />
max log size = 50<br />
local master = no<br />
domain master = no<br />
preferred master = no<br />
security = ADS<br />
password server =  your.AD.server<br />
encrypt passwords = yes<br />
socket options = TCP_NODELAY SO_RCVBUF=8192 SO_SNDBUF=8192<br />
wins proxy = no<br />
dns proxy = no<br />
winbind enum users = yes<br />
winbind enum groups = yes<br />
winbind use default domain = yes<br />
winbind separator = +<br />
winbind refresh tickets = yes<br />
idmap uid = 10000-20000<br />
idmap gid = 10000-20000</p>
<p>[public]<br />
path = /opt/data/samba/public<br />
comment = Public access folder<br />
read only = no<br />
force user = %U<br />
force group = &#8220;DOMAIN+domain users&#8221;<br />
force create mode = 0666<br />
force directory mode = 2777<br />
force directory security mode = 0777<br />
valid users = @&#8221;DOMAIN+domain users&#8221;</p>
<p>[restricted]<br />
path = /opt/data/samba/it<br />
comment = Restricted access folder<br />
writable = yes<br />
force user = %U<br />
force group = &#8220;DOMAIN+&lt;AD group that is allowed to access&gt;&#8221;<br />
force create mode = 0660<br />
create mask = 0660<br />
force directory mode = 0770<br />
force directory security mode = 0770<br />
valid users = @&#8221;DOMAIN+&lt;AD group that is allowed to access&gt;&#8221;</p></blockquote>
<p style="text-align: left;">
<p style="text-align: left;">I will explain some of the configuration directives used here for smb.conf. The first two are:</p>
<blockquote>
<p style="text-align: left;">security = ADS<br />
password server = your.AD.server</p></blockquote>
<p style="text-align: left;">This will tell Samba to use Active Directory security and that the server Samba needs to verify the passwords against is the local domain controller (the one that holds the AD tree).</p>
<p style="text-align: left;">The next two are:</p>
<blockquote>
<p style="text-align: left;">winbind use default domain = yes<br />
winbind separator = +</p></blockquote>
<p style="text-align: left;">If the first directive is set to &#8220;yes&#8221;, you won&#8217;t need to use the domain also when setting file permissions. Samba / Winbind will know to use what you have set in the &#8220;realm&#8221; directive in front of every group / user used for authentication or authorization. The second one just tells Samba what to use as separator between the &#8220;realm&#8221; and user or group.</p>
<p style="text-align: left;">This directive:</p>
<blockquote>
<p style="text-align: left;">winbind refresh tickets = yes</p>
</blockquote>
<p style="text-align: left;">will tell Samba to refresh the kerberos tickets after joining the domain, as not to &#8220;unjoin&#8221; it and become unable to authenticate against the AD.</p>
<p style="text-align: left;">As for the shares, you can use the variable &#8220;%U&#8221; as the authenticated user to force the ownership or to grant access. Also, you can use groups in the AD to allow access using the directive &#8220;valid users =&#8221; followed by the name of the group with the domain in front.</p>
<p style="text-align: left;">Example: valid users = @&#8221;DOMAIN+restricted-access-group&#8221; . Please use the separator that you have set above with &#8220;winbind separator&#8221;</p>
<p style="text-align: left;">The rest of the directives are usual Samba directives.</p>
<p style="text-align: left;">Now restart Samba and Winbind:</p>
<p style="text-align: left;">&#8221; sudo /etc/init.d/samba restart &#8221;<br />
&#8221; sudo /etc/init.d/winbind restart &#8221;</p>
<p style="text-align: left;"><strong>Joining the domain</strong></p>
<p style="text-align: left;">For Samba to be able the verify usernames and passwords against the Active Directory, the server must first be joined in the domain. To do that we need to use the &#8220;net ads join&#8221; command:</p>
<p style="text-align: left;">&#8221; net ads join -S your.AD.server -U user%password &#8220;</p>
<p style="text-align: left;">The user and password must be valid a valid user in the domain that has the permission to join it.</p>
<p style="text-align: left;">To verify that the server has joined the domain you can use the following commands:</p>
<p style="text-align: left;">&#8221; net ads status -S your.AD.server -U user%password &#8220;</p>
<p style="text-align: left;">or</p>
<p style="text-align: left;">&#8221; net ads info &#8220;</p>
<p style="text-align: left;">Also, to be safe run the following commands:</p>
<p style="text-align: left;">&#8221; wbinfo -u &#8220;</p>
<p style="text-align: left;">&#8221; wbinfo -g &#8220;</p>
<p style="text-align: left;">The first one should list all the domain users and the second one the domain groups. If this is so and you have seen the user and group list that means that the server is joined and is able to see verify the usernames / passwords.</p>
<p style="text-align: left;"><strong>Setting file permissions</strong></p>
<p style="text-align: left;">Now that Samba is configured and the server joined the domain, the last thing to do is to set the Unix style file permissions on the share folders. But now, you can use the users and groups in the domain as the owner and group settings of the folders and files. For example:</p>
<p style="text-align: left;">&#8221; chown &#8220;jon.doe&#8221; /opt/data/samba/restricted -R &#8220;</p>
<p style="text-align: left;">&#8221; chgrp &#8220;restricted-access-group&#8221; /opt/data/samba/restricted -R &#8220;</p>
<p style="text-align: left;">&#8221; chmod g+rw /opt/data/samba/restricted -R &#8220;</p>
<p style="text-align: left;">or to make all the users in the domain able to read and write the public folder:</p>
<p style="text-align: left;">&#8221; chgrp &#8220;domain users&#8221; /opt/data/samba/public -R &#8220;</p>
<p style="text-align: left;">&#8221; chmod g+rw /opt/data/samba/public -R &#8220;</p>
<p style="text-align: left;">That&#8217;s it! Now you should be able to access Samba shares using your AD username and password!</p>
<blockquote>
<p style="text-align: left;">
</blockquote>
<p style="text-align: left;">
]]></content:encoded>
			<wfw:commentRss>http://www.hostatic.ro/2009/06/03/configuring-a-samba-file-sharing-server-with-active-directory-authentication/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

