<?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:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Chamith Kumarage's guide 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>Tour to various corners of GNU/Linux systems administration</description>
	<lastBuildDate>Tue, 05 May 2009 17:08:24 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='saguide.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/8747826649017e731b7efac461cfeef6?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>Chamith Kumarage's guide for Systems Administrators</title>
		<link>http://saguide.wordpress.com</link>
	</image>
			<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 --color=auto'
alias rm='rm -i'
As [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=saguide.wordpress.com&blog=5170978&post=136&subd=saguide&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><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://s.wordpress.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://s.wordpress.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>
<p><iframe src='http://digg.com/api/diggthis.php?u=http%3A%2F%2Fdigg.com%2Flinux_unix%2FBash_Tips_and_Tricks_2_2' height='82' width='55' frameborder='0' scrolling='no' style='float: right; margin-left: 10px; margin-bottom: 5px; padding: 4px 0 2px 4px; background: #fff;'></iframe></p>
  <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/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&blog=5170978&post=136&subd=saguide&ref=&feed=1" /></div>]]></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 important that [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=saguide.wordpress.com&blog=5170978&post=121&subd=saguide&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><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 &#8217;su&#8217; to<br />
become root.  Tries to &#8217;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>
<p><iframe src='http://digg.com/api/diggthis.php?u=http%3A%2F%2Fdigg.com%2Fsecurity%2F13_security_practices_for_a_SysAdmin' height='82' width='55' frameborder='0' scrolling='no' style='float: right; margin-left: 10px; margin-bottom: 5px; padding: 4px 0 2px 4px; background: #fff;'></iframe></p>
  <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/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&blog=5170978&post=121&subd=saguide&ref=&feed=1" /></div>]]></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>Bash Tips and Tricks &#8211; 1</title>
		<link>http://saguide.wordpress.com/2008/12/07/bash-tips-and-tricks-1/</link>
		<comments>http://saguide.wordpress.com/2008/12/07/bash-tips-and-tricks-1/#comments</comments>
		<pubDate>Sun, 07 Dec 2008 16:41:08 +0000</pubDate>
		<dc:creator>saguide</dc:creator>
				<category><![CDATA[HOW TO]]></category>
		<category><![CDATA[Bash]]></category>
		<category><![CDATA[Bash find]]></category>
		<category><![CDATA[Bash loops]]></category>
		<category><![CDATA[CLI]]></category>
		<category><![CDATA[Command line]]></category>
		<category><![CDATA[Redirecting errors]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Tricks]]></category>

		<guid isPermaLink="false">http://saguide.wordpress.com/?p=112</guid>
		<description><![CDATA[Bash, or the Bourne Again Shell, is the default shell in most Linux distributions. The popularity of the bash shell amongst Linux and UNIX users is no accident. It has many features to enhance user-friendliness and productivity. Unfortunately, you can&#8217;t take advantage of those features unless you know they exist.
When I first started using Linux, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=saguide.wordpress.com&blog=5170978&post=112&subd=saguide&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Bash, or the Bourne Again Shell, is the default shell in most Linux distributions. The popularity of the bash shell amongst Linux and UNIX users is no accident. It has many features to enhance user-friendliness and productivity. Unfortunately, you can&#8217;t take advantage of those features unless you know they exist.</p>
<p>When I first started using Linux, the only bash feature I took advantage of was going back through the command history using the up arrow. I soon learned additional features by watching others and asking questions. In this article, I&#8217;d like to share some bash tricks I&#8217;ve learned over the years.</p>
<p>This article isn&#8217;t meant to cover all of the features of the bash shell; that would require a book, and plenty of books are available that cover this topic. Instead, this article is a summary of the bash tricks I use most often and would be lost without.</p>
<p><strong> Brace Expansion</strong></p>
<p>One of my favorite bash tricks is brace expansion. Brace expansion takes a list of strings separated by commas and expands those strings into separate arguments for you. The list is enclosed by braces, the symbols { and }, and there should be no spaces around the commas. For example:</p>
<pre class="programlisting">$ echo {one,two,red,blue}
one two red blue</pre>
<p>Using brace expansion as illustrated in this simple example doesn&#8217;t offer too much to the user. In fact, the above example requires typing two more characters than simply typing:</p>
<pre class="programlisting">echo one two red blue</pre>
<p>which produces the same result. However, brace expansion becomes quite useful when the brace-enclosed list occurs immediately before, after or inside another string:</p>
<pre class="programlisting">$ echo {one,two,red,blue}baloon
onebaloon twobaloon redbaloon bluebaloon

$ echo fish{one,two,red,blue}
fishone fishtwo fishred fishblue

$ echo fi{one,two,red,blue}sh
fionesh fitwosh firedsh fibluesh</pre>
<p>Notice that there are no spaces inside the brackets or between the brackets and the adjoining strings. If you include spaces, it breaks things:</p>
<pre class="programlisting">$ echo {one, two, red, blue }fi
{one, two, red, blue }fi

$ echo "{one,two,red,blue} fi"
{one,two,red,blue} fi</pre>
<p>However, you can use spaces if they&#8217;re enclosed in quotes outside the braces or within an item in the comma-separated list:</p>
<pre class="programlisting">$ echo {"one ","two ","red ","blue "}fish
one fish two fish red fish blue fish

$ echo {one,two,red,blue}" fish"
one fish two fish red fish blue fish</pre>
<p>You also can nest braces, but you must use some caution here too:</p>
<pre class="programlisting">$ echo {{1,2,3},1,2,3}
1 2 3 1 2 3

$ echo {{1,2,3}1,2,3}
11 21 31 2 3</pre>
<p>Now, after all these examples, you might be thinking to yourself, “Those are great parlor tricks, but why should I care about brace expansion?”</p>
<p>Brace expansion becomes useful when you need to make a backup of a file. This is why it&#8217;s my favorite shell trick. I use it almost every day when I need to make a backup of a config file before changing it. For example, if I&#8217;m making a change to my Apache configuration, I can do the following and save some typing:</p>
<pre class="programlisting">$ cp /etc/apache2/apache2.conf{,.bak}</pre>
<p>Notice that there is no character between the opening brace and the first comma. It&#8217;s perfectly acceptable to do this and is useful when adding characters to an existing filename or when one argument is a substring of the other. Then, if I need to see what changes I made later in the day, I use the <em>diff</em> command and reverse the order of the strings inside the braces:</p>
<pre class="programlisting">$ diff /etc/apache2/apache2.conf{.bak,}
1050a1051
&gt; # I added this comment earlier</pre>
<p><strong> Redirecting Standard Error</strong></p>
<p>Have you ever looked for a file using the <em><tt>find</tt></em> command, only to learn the file you were looking for is lost in a sea of <tt>permission denied</tt> error messages that quickly fill your terminal window?</p>
<p>If you are the administrator of the system, you can become root and execute <em><tt>find</tt></em> again as root. Because root can read any file, you don&#8217;t get that error anymore. Unfortunately, not everyone has root access on the system being used. Besides, it&#8217;s bad practice to be root unless it&#8217;s absolutely necessary. So what can you do?</p>
<p>One thing you can do is redirect your output to a file. Basic output redirection should be nothing new to anyone who has spent a reasonable amount of time using any UNIX or Linux shell, so I won&#8217;t go into detail regarding the basics of output redirection. To save the useful output from the <em>find</em> command, you can redirect the output to a file:</p>
<pre class="programlisting">$ find /  -name foo &gt; output.txt</pre>
<p>You still see the error messages on the screen but not the path of the file you&#8217;re looking for. Instead, that is placed in the file output.txt. When the find command completes, you can <tt>cat</tt> the file output.txt to get the location(s) of the file(s) you want.</p>
<p>That&#8217;s an acceptable solution, but there&#8217;s a better way. Instead of redirecting the standard output to a file, you can redirect the error messages to a file. This can be done by placing a 2 directly in front of the redirection angle bracket. If you are not interested in the error messages, you simply can send them to <em>/dev/null</em>:</p>
<div class="simplesect" lang="en">
<pre class="programlisting">$ find /  -name foo 2&gt; /dev/null</pre>
</div>
<div class="simplesect" lang="en">
<div class="titlepage"><a name="N0xa50890.0xb45eb0"></a></div>
<p>This shows you the location of file foo, if it exists, without those pesky <tt>permission denied</tt> error messages. I almost always invoke the find command in this way.</p>
<p>The number 2 represents the standard error output stream. Standard error is where most commands send their error messages. Normal (non-error) output is sent to standard output, which can be represented by the number 1. Because most redirected output is the standard output, output redirection works only on the standard output stream by default. This makes the following two commands equivalent:</p>
<pre class="programlisting">$ find / -name foo &gt; output.txt
$ find / -name foo 1&gt; output.txt</pre>
</div>
<p>Sometimes you might want to save both the error messages and the standard output to file. This often is done with cron jobs, when you want to save all the output to a log file. This also can be done by directing both output streams to the same file:</p>
<pre class="programlisting">$ find / -name foo &gt; output.txt 2&gt; output.txt</pre>
<p>This works, but again, there&#8217;s a better way to do it. You can tie the standard error stream to the standard output stream using an ampersand. Once you do this, the error messages goes to wherever you redirect the standard output:</p>
<pre class="programlisting">$ find / -name foo &gt; output.txt 2&gt;&amp;1</pre>
<p>One caveat about doing this is that the tying operation goes at the end of the command generating the output. This is important if piping the output to another command. This line works as expected:</p>
<pre class="programlisting">find -name test.sh 2&gt;&amp;1 | tee /tmp/output2.txt</pre>
<p>but this line doesn&#8217;t:</p>
<pre class="programlisting">find -name test.sh | tee /tmp/output2.txt 2&gt;&amp;1</pre>
<p>and neither does this one:</p>
<pre class="programlisting">find -name test.sh 2&gt;&amp;1 &gt; /tmp/output.txt</pre>
<p>I started this discussion on output redirection using the find command as an example, and all the examples used the find command. This discussion isn&#8217;t limited to the output of find, however. Many other commands can generate enough error messages to obscure the one or two lines of output you need.</p>
<p>Output redirection isn&#8217;t limited to bash, either. All UNIX/Linux shells support output redirection using the same syntax.</p>
<p><strong> Using Loops from the Command Line</strong></p>
<p>One last tip I&#8217;d like to offer is using loops from the command line. The command line is not the place to write complicated scripts that include multiple loops or branching. For small loops, though, it can be a great time saver. Unfortunately, I don&#8217;t see many people taking advantage of this. Instead, I frequently see people use the up arrow key to go back in the command history and modify the previous command for each iteration.</p>
<p>If you are not familiar with creating for loops or other types of loops, many good books on shell scripting discuss this topic. A discussion on for loops in general is an article in itself.</p>
<p>You can write loops interactively in two ways. The first way, and the method I prefer, is to separate each line with a semicolon. A simple loop to make a backup copy of all the files in a directory would look like this:</p>
<pre class="programlisting">$ for file in * ; do cp $file $file.bak; done</pre>
<p>Another way to write loops is to press Enter after each line instead of inserting a semicolon. bash recognizes that you are creating a loop from the use of the for keyword, and it prompts you for the next line with a secondary prompt. It knows you are done when you enter the keyword done, signifying that your loop is complete:</p>
<pre class="programlisting">$ for file in *
&gt; do cp $file $file.bak
&gt; done</pre>
<div class="titlepage">And Now for Something Completely Different</div>
<p>When I originally conceived this article, I was going to name it “Stupid bash Tricks”, and show off some unusual, esoteric bash commands I&#8217;ve learned. The tone of the article has changed since then, but there is one stupid bash trick I&#8217;d like to share.</p>
<p>About 2 years ago, a Linux system I was responsible for ran out of memory. Even simple commands, such as<em> ls</em>, failed with an <tt>insufficient memory</tt> error. The obvious solution to this problem was simply to reboot. One of the other system administrators wanted to look at a file that may have held clues to the problem, but he couldn&#8217;t remember the exact name of the file. We could switch to different directories, because the <em>cd</em> command is part of bash, but we couldn&#8217;t get a list of the files, because even ls would fail. To get around this problem, the other system administrator created a simple loop to show us the files in the directory:</p>
<pre class="programlisting">$ for file in *; do echo $file; done</pre>
<p>This worked when ls wouldn&#8217;t, because <em>echo</em> is a part of the bash shell, so it already is loaded into memory. It&#8217;s an interesting solution to an unusual problem. Now, can anyone suggest a way to display the contents of a file using only bash built-ins?</p>
<p><strong>Conclusion</strong></p>
<p>Bash has many great features to make life easier for its users. I hope this summary of bash tricks I like to use has shown you some new ways to take advantage of the power bash has to offer.</p>
<p><iframe src='http://digg.com/api/diggthis.php?u=http%3A%2F%2Fdigg.com%2Flinux_unix%2FBash_Tips_and_Tricks_2' height='82' width='55' frameborder='0' scrolling='no' style='float: right; margin-left: 10px; margin-bottom: 5px; padding: 4px 0 2px 4px; background: #fff;'></iframe></p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/saguide.wordpress.com/112/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/saguide.wordpress.com/112/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/saguide.wordpress.com/112/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/saguide.wordpress.com/112/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/saguide.wordpress.com/112/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/saguide.wordpress.com/112/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/saguide.wordpress.com/112/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/saguide.wordpress.com/112/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/saguide.wordpress.com/112/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/saguide.wordpress.com/112/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=saguide.wordpress.com&blog=5170978&post=112&subd=saguide&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://saguide.wordpress.com/2008/12/07/bash-tips-and-tricks-1/feed/</wfw:commentRss>
		<slash:comments>5</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 Postfix or Sendmail, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=saguide.wordpress.com&blog=5170978&post=92&subd=saguide&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><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>
<p><iframe src='http://digg.com/api/diggthis.php?u=http%3A%2F%2Fdigg.com%2Flinux_unix%2FMail_server_setup_with_Qmail' height='82' width='55' frameborder='0' scrolling='no' style='float: right; margin-left: 10px; margin-bottom: 5px; padding: 4px 0 2px 4px; background: #fff;'></iframe></p>
  <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/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&blog=5170978&post=92&subd=saguide&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://saguide.wordpress.com/2008/11/16/mail-server-setup-with-qmail/feed/</wfw:commentRss>
		<slash:comments>5</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&blog=5170978&post=82&subd=saguide&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><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>
<p><iframe src='http://digg.com/api/diggthis.php?u=http%3A%2F%2Fdigg.com%2Fsecurity%2FConfigure_Squid_to_control_web_access' height='82' width='55' frameborder='0' scrolling='no' style='float: right; margin-left: 10px; margin-bottom: 5px; padding: 4px 0 2px 4px; background: #fff;'></iframe></p>
<p>Reference:</p>
<p>http://www.squid-cache.org/</p>
<p>Special thanks to Peter Harrison.</p>
  <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/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&blog=5170978&post=82&subd=saguide&ref=&feed=1" /></div>]]></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  [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=saguide.wordpress.com&blog=5170978&post=65&subd=saguide&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><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://s.wordpress.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>
<p><iframe src='http://digg.com/api/diggthis.php?u=http%3A%2F%2Fdigg.com%2Fsecurity%2FSecuring_your_wireless_network_6' height='82' width='55' frameborder='0' scrolling='no' style='float: right; margin-left: 10px; margin-bottom: 5px; padding: 4px 0 2px 4px; background: #fff;'></iframe></p>
  <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/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&blog=5170978&post=65&subd=saguide&ref=&feed=1" /></div>]]></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>
		<item>
		<title>How BitTorrent works</title>
		<link>http://saguide.wordpress.com/2008/10/19/how-bittorrent-works/</link>
		<comments>http://saguide.wordpress.com/2008/10/19/how-bittorrent-works/#comments</comments>
		<pubDate>Sun, 19 Oct 2008 19:00:45 +0000</pubDate>
		<dc:creator>saguide</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[BitTorrent]]></category>
		<category><![CDATA[Download]]></category>
		<category><![CDATA[P2P]]></category>

		<guid isPermaLink="false">http://saguide.wordpress.com/?p=55</guid>
		<description><![CDATA[In 2001, a computer geek named Bram Cohen (25) visited the annual DefCon &#8216;hacker&#8217; convention in Las Vegas to show off his new toy&#8230; BitTorrent. It then debuted at CodeCon 2002 the following year and gained popularity, being featured on an online P2P magazine as well as a few respectable news sites. Fast forward a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=saguide.wordpress.com&blog=5170978&post=55&subd=saguide&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>In 2001, a computer geek named Bram Cohen (25) visited the annual DefCon &#8216;hacker&#8217; convention in Las Vegas to show off his new toy&#8230; BitTorrent. It then debuted at CodeCon 2002 the following year and gained popularity, being featured on an online P2P magazine as well as a few respectable news sites. Fast forward a few years, and a significant percentage of internet traffic belongs to BitTorrent usage, the MPAA and RIAA hate it and Microsoft is at tempting (unsuccessfully) to copy it.</p>
<p><strong>How it works<br />
</strong></p>
<p>Let&#8217;s take a general example here. Imagine you are in a room with three other people. One of these people (let&#8217;s call him A) has a complete jigsaw puzzle with him. The objective is to transfer a copy of the jigsaw to each of the other three people in the room in the most efficient way possible. Initially &#8216;A&#8217; transfers a portion of the file to a person in the room. Simultaneously, he transfers a different portion to the other, and yet another portion to you. Now we have three different portions of the jigsaw puzzle, which if put together make one hundred percent. While &#8216;A&#8217; continues to transfer the rest of the file, each person in the room can now transfer their portions to each other as well.</p>
<p>Let&#8217;s get a little geeky and use BitTorrent lingo, which you will need to know if you ever decide to venture into torrent territory. The jigsaw here is a file..let&#8217;s say a movie (movie.avi). &#8216;A&#8217;, who has the complete file is called a &#8216;<em>seed</em>&#8216;. The person who doesn&#8217;t have the complete file is called a &#8216;<em>leech</em>&#8216; or &#8216;<em>leecher</em>&#8216;. Both these types can be commonly called a &#8216;<em>peer</em>&#8216;. For example, if someone says &#8220;I&#8217;m downloading this file off 1 seed and 3 leechers&#8221;, that means he&#8217;s connected to and downloading from 4 peers. So what happens is, a seed sends a different parts of the file to each leecher. Each leacher in turn transfers parts of the file to other leechers. This way, if a seed disconnects, 100% of the file will still be able to downloaded since there&#8217;s a full copy amongst the leechers.</p>
<p><strong>Do it yourself</strong></p>
<p>Now that you know how the protocol works, it&#8217;s time foe some hands-on experience. You&#8217;ll be happy to know that all software need to delve into the BitTorrent world is free&#8230;and free of spyware/malware/adware and other annoying *ware&#8217;s.</p>
<p>In the BitTorrent world, all you download  off websites are small files called &#8216;torrents&#8217; (with a .torrent extension) Once you download the torrent onto your computer, you run it with a BitTorrent client. The BitTorrent client will handle the rest for you.</p>
<p><strong>BitTorrent client</strong></p>
<p>There are as many BitTorrent client&#8217;s out there as there are budding rock groups in the world. Each client have it&#8217;s own streangths and weaknesses. I recommend &#8216;<a title="qbittorrent official site" href="http://qbittorrent.sourceforge.net/" target="_blank">qbittorrent</a>&#8216; which I myself use, though there are other really good torrent clients. The official BitTorrent client is available at <a title="BitTorrent official site" href="http://www.bittorrent.com/" target="_blank">BitTorrent.com</a> and a simple Google search will link you to many more.</p>
<p>The client is the software that keeps track of all your downloads. It&#8217;ll also present you with more information than you&#8217;ll know what to do with. Your client can allow you to &#8216;chat&#8217; to others, prioritize certain files in the torrent, etc. If I just confused you..that&#8217;s okay, you probably don&#8217;t need those features anyway.</p>
<p><strong>Torrents</strong></p>
<p>After you have downloaded and installed a BitTorrent client, you will need to find yourself a torrent of your choice. These can be downloaded off from the websites. Usually these sites have search facility  which allows you to search for the torrents you want. You don&#8217;t have to worry about the file size, because torrent files are usually less than 50kb&#8217;s in size. (If you are using &#8216;<em>qbittorrent</em>&#8216; it has a build in torrent search engine which enables you to download torrents from various torrent sites)</p>
<p>At this point many users new to torrents are surprised at how a 700mb &#8216;<em>movie.avi</em>&#8216; downloaded in 5 seconds. It didn&#8217;t. What actually downloaded is the TORRENT file. Think of a torrent as a small file telling your BitTorrent client where to find the actual &#8216;<em>movie.avi</em>&#8216; file from.</p>
<p>Great! At this point you have the items on my very short &#8216;what you need&#8217; list. The complicated part is over. Next open the torrent file with your chosen BitTorrent client. That&#8217;s it! Now you can leave your computer and indulge in your favorite extra curricular activity while the torrent downloads.</p>
<p><strong>Future of BitTorrent</strong></p>
<p>BitTorrent, Inc. is continuously working on making a more efficient delivery network. BitTorrent DNA<sup>TM</sup> is their next step in the evolution of digital content delivery; it combines the extreme efficiency and organic scalability of peer networking with the control and reliability of a traditional content delivery network (CDN). BitTorrent DNA uses one or more existing origin servers or CDNs to seed a managed peer network.</p>
<p align="left">Use of the peer network is tightly controlled by a specialized tracker operated by BitTorrent, Inc. and accessible to BitTorrent DNA customers through a web-based dashboard that provides control and reporting tools.</p>
<p align="left">Thanks to Raveen Wijayatilake and BitTorrent, Inc.</p>
<p><iframe src='http://digg.com/api/diggthis.php?u=http%3A%2F%2Fdigg.com%2Fgadgets%2FHow_BitTorrent_works_6' height='82' width='55' frameborder='0' scrolling='no' style='float: right; margin-left: 10px; margin-bottom: 5px; padding: 4px 0 2px 4px; background: #fff;'></iframe></p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/saguide.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/saguide.wordpress.com/55/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/saguide.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/saguide.wordpress.com/55/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/saguide.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/saguide.wordpress.com/55/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/saguide.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/saguide.wordpress.com/55/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/saguide.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/saguide.wordpress.com/55/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=saguide.wordpress.com&blog=5170978&post=55&subd=saguide&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://saguide.wordpress.com/2008/10/19/how-bittorrent-works/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>System Administrators&#8217; Code of Ethics</title>
		<link>http://saguide.wordpress.com/2008/10/14/system-administrators-code-of-ethics/</link>
		<comments>http://saguide.wordpress.com/2008/10/14/system-administrators-code-of-ethics/#comments</comments>
		<pubDate>Tue, 14 Oct 2008 17:55:43 +0000</pubDate>
		<dc:creator>saguide</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Administrator]]></category>
		<category><![CDATA[Ethics]]></category>
		<category><![CDATA[Systems]]></category>

		<guid isPermaLink="false">http://saguide.wordpress.com/?p=37</guid>
		<description><![CDATA[Professionalism


I 	will maintain professional conduct in the workplace and will not 	allow personal feelings or beliefs to cause me to treat people 	unfairly or unprofessionally. 


Personal Integrity


I 	will be honest in my professional dealings and forthcoming about my 	competence and the impact of my mistakes. I will seek assistance 	from others when required. 


I 	will [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=saguide.wordpress.com&blog=5170978&post=37&subd=saguide&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><strong><span style="font-family:ae_AlYermook;">Professionalism</span></strong></p>
<ul>
<li>
<p style="line-height:150%;" align="justify"><span style="font-family:ae_AlYermook;">I 	will maintain professional conduct in the workplace and will not 	allow personal feelings or beliefs to cause me to treat people 	unfairly or unprofessionally. </span></p>
</li>
</ul>
<p><strong><span style="font-family:ae_AlYermook;">Personal Integrity</span></strong></p>
<ul>
<li>
<p style="margin-bottom:0;line-height:150%;" align="justify"><span style="font-family:ae_AlYermook;">I 	will be honest in my professional dealings and forthcoming about my 	competence and the impact of my mistakes. I will seek assistance 	from others when required. </span></p>
</li>
<li>
<p style="line-height:150%;" align="justify"><span style="font-family:ae_AlYermook;">I 	will avoid conflicts of interest and biases whenever possible. When 	my advice is sought, if I have a conflict of interest or bias, I 	will declare it if appropriate, and recuse myself if necessary. </span></p>
</li>
</ul>
<p><strong><span style="font-family:ae_AlYermook;">Privacy</span></strong></p>
<ul>
<li>
<p style="line-height:150%;" align="justify"><span style="font-family:ae_AlYermook;">I 	will access private information on computer systems only when it is 	necessary in the course of my technical duties. I will maintain and 	protect the confidentiality of any information to which I may have 	access, regardless of the method by which I came into knowledge of 	it. </span></p>
</li>
</ul>
<p><strong><span style="font-family:ae_AlYermook;">Laws and Policies</span></strong></p>
<ul>
<li>
<p style="line-height:150%;" align="justify"><span style="font-family:ae_AlYermook;">I 	will educate myself and others on relevant laws, regulations, and 	policies regarding the performance of my duties. </span></p>
</li>
</ul>
<p><strong><span style="font-family:ae_AlYermook;">Communication</span></strong></p>
<ul>
<li>
<p style="line-height:150%;" align="justify"><span style="font-family:ae_AlYermook;">I 	will communicate with management, users, and colleagues about 	computer matters of mutual interest. I will strive to listen to and 	understand the needs of all parties. </span></p>
</li>
</ul>
<p><strong><span style="font-family:ae_AlYermook;">System Integrity</span></strong></p>
<ul>
<li>
<p style="margin-bottom:0;line-height:150%;" align="justify"><span style="font-family:ae_AlYermook;">I 	will strive to ensure the necessary integrity, reliability, and 	availability of the systems for which I am responsible. </span></p>
</li>
<li>
<p style="line-height:150%;" align="justify"><span style="font-family:ae_AlYermook;">I 	will design and maintain each system in a manner to support the 	purpose of the system to the organization. </span></p>
</li>
</ul>
<p><strong><span style="font-family:ae_AlYermook;">Education</span></strong></p>
<ul>
<li>
<p style="line-height:150%;" align="justify"><span style="font-family:ae_AlYermook;">I 	will continue to update and enhance my technical knowledge and other 	work-related skills. I will share my knowledge and experience with 	others. </span></p>
</li>
</ul>
<p><strong><span style="font-family:ae_AlYermook;">Responsibility to Computing Community</span></strong></p>
<ul>
<li>
<p style="line-height:150%;" align="justify"><span style="font-family:ae_AlYermook;">I 	will cooperate with the larger computing community to maintain the 	integrity of network and computing resources. </span></p>
</li>
</ul>
<p><strong><span style="font-family:ae_AlYermook;">Social Responsibility</span></strong></p>
<ul>
<li>
<p style="line-height:150%;" align="justify"><span style="font-family:ae_AlYermook;">As 	an informed professional, I will encourage the writing and adoption 	of relevant policies and laws consistent with these ethical 	principles. </span></p>
</li>
</ul>
<p><strong><span style="font-family:ae_AlYermook;">Ethical Responsibility</span></strong></p>
<ul>
<li>
<p style="margin-bottom:0;line-height:150%;" align="justify"><span style="font-family:ae_AlYermook;">I 	will strive to build and maintain a safe, healthy, and productive 	workplace. </span></p>
</li>
<li>
<p style="margin-bottom:0;line-height:150%;" align="justify"><span style="font-family:ae_AlYermook;">I 	will do my best to make decisions consistent with the safety, 	privacy, and well-being of my community and the public, and to 	disclose promptly factors that might pose unexamined risks or 	dangers. </span></p>
</li>
<li>
<p style="margin-bottom:0;line-height:150%;" align="justify"><span style="font-family:ae_AlYermook;">I 	will accept and offer honest criticism of technical work as 	appropriate and will credit properly the contributions of others. </span></p>
</li>
<li>
<p style="line-height:150%;" align="justify"><span style="font-family:ae_AlYermook;">I 	will lead by example, maintaining a high ethical standard and degree 	of professionalism in the performance of all my duties. I will 	support colleagues and co-workers in following this code of ethics.</span></p>
</li>
</ul>
<p style="line-height:150%;text-align:left;"><em><span style="font-family:ae_AlYermook;">approved by the SAGE Executive Committee and  by the Ethics Working Group.</span></em></p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/saguide.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/saguide.wordpress.com/37/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/saguide.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/saguide.wordpress.com/37/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/saguide.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/saguide.wordpress.com/37/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/saguide.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/saguide.wordpress.com/37/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/saguide.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/saguide.wordpress.com/37/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=saguide.wordpress.com&blog=5170978&post=37&subd=saguide&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://saguide.wordpress.com/2008/10/14/system-administrators-code-of-ethics/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>Rename a list in Mailman</title>
		<link>http://saguide.wordpress.com/2008/10/14/rename-a-list-in-mailman/</link>
		<comments>http://saguide.wordpress.com/2008/10/14/rename-a-list-in-mailman/#comments</comments>
		<pubDate>Tue, 14 Oct 2008 15:56:15 +0000</pubDate>
		<dc:creator>saguide</dc:creator>
				<category><![CDATA[HOW TO]]></category>
		<category><![CDATA[mailing list]]></category>
		<category><![CDATA[Mailman]]></category>

		<guid isPermaLink="false">http://saguide.wordpress.com/?p=19</guid>
		<description><![CDATA[Before read any further, make sure that you have administrator privileges for system-wide operations. Because you need to have access to the Mailman installation to perform the operations which I&#8217;m gonna tell you shortly. If you don&#8217;t have this access, you need to create a new list and configure like the old one. Hm.. think [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=saguide.wordpress.com&blog=5170978&post=19&subd=saguide&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Before read any further, make sure that you have administrator privileges for system-wide operations. Because you need to have access to the Mailman installation to perform the operations which I&#8217;m gonna tell you shortly. If you don&#8217;t have this access, you need to create a new list and configure like the old one. Hm.. think of a mailing list with a few hundred users and hell a lot of configuration <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>If you have access to the command line tools, you can simplify the whole process by doing the following after creating the new list:</p>
<pre> [root]# <strong>cd &lt;mailman_installation&gt;</strong> ; usually at /var/lib/mailman
 [root]# <strong>bin/config_list -o file oldlist</strong>
 [root]# <strong>bin/config_list -i file newlist</strong>
 [root]# <strong>bin/list_members -o digest_file -p -d -f oldlist</strong>
 [root]# <strong>bin/list_members -o regular_file -p -r -f oldlist</strong>
 [root]# <strong>bin/add_members -d digest_file -r regular_file [other options] newlist
</strong></pre>
<p>Use the <strong>&#8211;help</strong> options on the above commands for more information.</p>
<p>The drawback of the above methods is member information other than name and regular/digest is not transferred and the archives are not transferred. The following procedure will preserve everything. Before doing this, consider whether you want to stop your incoming MTA during the process to prevent possible message loss.</p>
<pre> [root]# <strong>mv lists/oldlist lists/newlist</strong>
 [root]# <strong>mv archives/private/oldlist archives/private/newlist</strong>
 [root]# <strong>mv archives/private/oldlist.mbox archives/private/newlist.mbox</strong>
 [root]# <strong>mv archives/private/newlist.mbox/oldlist.mbox archives/private/newlist.mbox/newlist.mbox
</strong></pre>
<p>Then go to the web admin interface for the &#8216;newlist&#8217; list and change the real_name from &#8216;OldList&#8217; to &#8216;NewList&#8217;.</p>
<p>You might be tempted to change the names of any <em>data/heldmsg-oldlist-nnn.pck</em> (or .txt) files. Don&#8217;t do this. The old names are in the lists request.pck files, and changing the name will result in the file not being found.</p>
<p>Also, don&#8217;t be too concerned about symlinks in the <em>archives/public/</em> directory. Mailman will automatically create them as needed for the new name. If you leave the old symlinks, they will point to non-existant directories, and trying to visit old public archive URLs will probably give a 403 &#8211; forbidden error, so removing them is a good idea, but then visiting the old URLs will still produce a 404 &#8211; not found error.</p>
<p>At this point, everything is OK except the &#8216;more information about this list&#8217; links on some archive pages will still point to the &#8216;oldlist&#8217; list which doesn&#8217;t exist. You can fix those manually or rebuild the archive with:</p>
<pre> [root]# <strong>bin/arch --wipe newlist
</strong></pre>
<p>Finally, if your MTA uses aliases for mailman lists rather than some process that automatically understands list names from the contents of the <em>lists/</em> directory, you will have to update your aliases. If you do this manually, edit your aliases to change &#8216;oldlist&#8217; to &#8216;newlist&#8217; (a total of 2 changes per alias for 10 aliases), and then run &#8216;newaliases&#8217; or whatever command rebuilds your alias database. It you have Postfix/Mailman integration, just run <strong><em>bin/genaliases</em></strong>.</p>
<p>Depending upon your version of Mailman, you may find that after performing the second type of renaming procedure, above, that when you log into the admin screen for &#8216;NewList,&#8217; the list name in the first box still shows &#8216;OldList&#8217; and needs changing to &#8216;NewList.&#8217; Upon trying to submit that change, you may be presented with:</p>
<p><span style="color:red;">Error: real_name attribute not changed! It must differ from the list&#8217;s name by case only.</span></p>
<p>In that case, use the following commands to change the real_name:</p>
<pre>[root]# <strong>bin/withlist -l newname</strong>
 Loading list newname (locked)
 The variable `m' is the newname MailList instance
 &gt;&gt;&gt; m.real_name
 'OldName'
 &gt;&gt;&gt; m.real_name = 'NewName'
 &gt;&gt;&gt; m.Save()
 &gt;&gt;&gt;
 Unlocking (but not saving) list: newname
 Finalizing</pre>
<p>You type the withlist command, and within withlist, you type the responses to the &gt;&gt;&gt; prompts. On the &gt;&gt;&gt; last line, your entry is control-D (end of file). This procedure was found in the archives of the Mailman-Users mailing list:</p>
<p><a title="Mailman-Users archives" rel="nofollow" href="http://www.mail-archive.com/mailman-users@python.org/msg50278.html" target="_blank">http://www.mail-archive.com/mailman-users@python.org/msg50278.html</a></p>
<p>Enjoy!</p>
<p style="text-align:left;">Special Thanks to: David Topping and Mark Sapiro</p>
<p style="text-align:left;"><iframe src='http://digg.com/api/diggthis.php?u=http%3A%2F%2Fdigg.com%2Flinux_unix%2FRename_a_list_in_Mailman' height='82' width='55' frameborder='0' scrolling='no' style='float: right; margin-left: 10px; margin-bottom: 5px; padding: 4px 0 2px 4px; background: #fff;'></iframe></p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/saguide.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/saguide.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/saguide.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/saguide.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/saguide.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/saguide.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/saguide.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/saguide.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/saguide.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/saguide.wordpress.com/19/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=saguide.wordpress.com&blog=5170978&post=19&subd=saguide&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://saguide.wordpress.com/2008/10/14/rename-a-list-in-mailman/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>Configure Apache2 with SSL</title>
		<link>http://saguide.wordpress.com/2008/10/14/configure-apache2-with-ssl/</link>
		<comments>http://saguide.wordpress.com/2008/10/14/configure-apache2-with-ssl/#comments</comments>
		<pubDate>Tue, 14 Oct 2008 15:53:27 +0000</pubDate>
		<dc:creator>saguide</dc:creator>
				<category><![CDATA[HOW TO]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[HTTPS]]></category>
		<category><![CDATA[mod_ssl]]></category>
		<category><![CDATA[OpenSSL]]></category>
		<category><![CDATA[SSL]]></category>

		<guid isPermaLink="false">http://saguide.wordpress.com/?p=16</guid>
		<description><![CDATA[I recently had a need to setup a private directory on my web server that could only be accessed by a handful of selected people. The content also needed to be encrypted in transit. This article details how I did this on a Debian GNU/Linux system running Apache (2.0.40) server using mod_ssl and OpenSSL (0.9.6b [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=saguide.wordpress.com&blog=5170978&post=16&subd=saguide&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I recently had a need to setup a private directory on my web server that could only be accessed by a handful of selected people. The content also needed to be encrypted in transit. This article details how I did this on a <a title="Debian GNU/Linux" href="http://www.debian.org/" target="_blank">Debian GNU/Linux</a> system running <a title="Apache Foundation" href="http://apache.org/" target="_blank">Apache</a> (2.0.40) server using mod_ssl and <a title="OpenSSL Project" href="http://www.openssl.org/" target="_blank">OpenSSL</a> (0.9.6b and higher).  Here are the goals of this project:</p>
<ul>
<li>Require HIGH or MEDIUM level SSL/TLS encryption at the transport (TCP) layer</li>
<li>Browser must use SSLv3 or TLSv1, not SSLv2</li>
<li>Require username/password authentication for some subdirectories</li>
<li>Be a mini-CA (Certificate Authority)</li>
<li>Use a non-standard port to keep most of the port-scanning riffraff away</li>
</ul>
<p>The key to this whole system is the SSL/TLS protocol. SSL stands for Secure Sockets Layer, and it was developed by Netscape to enable secure transactions over the Web. It operates between the TCP layer and the HTTP application layer. TLSv1 is the IETF standard implementation, based on SSLv3. TLS stands for Transport Layer Security.</p>
<h3>Assumptions</h3>
<p>First and foremost, this document assumes that you are using some flavor of Linux, Apache 2.0.x and that you have OpenSSL installed. Other assumptions:</p>
<ul>
<li>This will be used over the Internet</li>
<li>Your DNS configuration is correct (hostname=FQDN, PTR records O.K., etc.)</li>
<li>Your firewall is setup to allow connections on the chosen https:// port</li>
<li>You have a second machine with a modern web browser for testing purposes</li>
<li>In these examples, my FQDN and hostname is:  <strong>mycompany.com</strong></li>
</ul>
<p><strong>Step 1:  Setup your own CA (Certificate Authority)</strong></p>
<p>In order to run a secure (SSL/TLS encrypted) web server, you have to have a private key and a certificate for the server. For a commercial web site, you will probably want to purchase a certificate signed by a well-known root CA. For Intranet or special-purpose uses like this, you can be your own CA. This is done with the OpenSSL tools.</p>
<p>Here, we will make a private CA key and a private CA X.509 certificate.  We will also make a directory for the  certs and keys:</p>
<pre>[root]# <strong>mkdir /root/CA</strong>
[root]# <strong>chmod 0770 /root/CA</strong>
[root]# <strong>cd /root/CA</strong>

[root]# <strong>openssl genrsa -des3 -out my-ca.key 2048</strong>
Generating RSA private key, 2048 bit long modulus
.....................................................+++
...................................................+++
e is 65537 (0x10001)
Enter PEM pass phrase:
Verifying password - Enter PEM pass phrase:

[root]# <strong>openssl req -new -x509 -days 3650 -key my-ca.key -out my-ca.crt</strong>
Using configuration from /usr/share/ssl/openssl.cnf
Enter PEM pass phrase:
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) []:LK
State or Province Name (full name) []:Western
Locality Name (eg, city) []:Colombo
Organization Name (eg, company) [My Company Ltd]:MyCompany.Com
Organizational Unit Name (eg, section) []:Certificate Authority
Common Name (eg, your name or your server's hostname) []:mycompany.com CA
Email Address []:user@mycompany.com

[root]# <strong>openssl x509 -in my-ca.crt -text -noout
</strong></pre>
<p><strong>Notes:</strong> The first OpenSSL command makes the key. The second command makes the X.509 certificate with a 10-year lifetime. The third command lets you view the completed certificate. Make sure that you keep the password in a safe place, you will need this every time you sign another certificate! You will probably also want to make backups of the cert and key and lock them in a safe place.</p>
<p><strong>Step 2:  Make a key and a certificate for the web server:</strong></p>
<p>Now, we have to make an X.509 certificate and corresponding private key for the web server. Rather than creating a certificate directly, we will create a key and a <em>certificate request</em>, then &#8220;sign&#8221; the certificate request with the CA key we made in Step 1. You can make keys for multiple web servers this way. One thing to note is that SSL/TLS private keys for web servers need to be either 512 or 1024 bits. Any other key size may be incompatible with certain browsers.</p>
<pre>[root]# <strong>openssl genrsa -des3 -out server.key 1024</strong>
Generating RSA private key, 1024 bit long modulus
....++++++
.++++++
e is 65537 (0x10001)
Enter PEM pass phrase:
Verifying password - Enter PEM pass phrase:

[root]# <strong>openssl req -new -key server.key -out server.csr</strong>
Using configuration from /usr/share/ssl/openssl.cnf
Enter PEM pass phrase:
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) []:LK
State or Province Name (full name) []:Western
Locality Name (eg, city) []:Colombo
Organization Name (eg, company) [My Company Ltd]:mycompany.Com
Organizational Unit Name (eg, section) []:TechStaff
Common Name (eg, your name or your server's hostname) []:mycompany.com <span style="color:#ff0000;"><strong>&lt;=== This must be the real FQDN of your server!!!</strong></span>
Email Address []:user@mycompany.com

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:

# <strong>openssl x509 -req -in server.csr -out server.crt -sha1 -CA my-ca.crt -CAkey my-ca.key -CAcreateserial -days 3650</strong>
Signature ok
subject=/C=LK/ST=Western/L=Colombo/O=mycompany.Com/OU=TechStaff/CN=mycompany.com/Email=user@mycompany.com
Getting CA Private Key
Enter PEM pass phrase:

[root]# <strong>openssl x509 -in server.crt -text -noout</strong></pre>
<p>Make sure that your server name is the same as the FQDN that your clients will use when connecting to your site. Also, let&#8217;s get in the habit of protecting our keys with appropriate permissions:</p>
<pre>[root]# <strong>chmod 0400 *.key
</strong></pre>
<p>Now, we need to move the new keys and certs into the proper directories in the /etc/apache2 hierarchy:</p>
<pre>[root]# <strong>cp server.crt /etc/apache2/ssl.crt</strong>
[root]# <strong>cp server.key /etc/apache2/ssl.key</strong>
[root]# <strong>cp my-ca.crt /etc/apache2/ssl.crt</strong></pre>
<p><strong>Step 3: Create directories and files for the secure web service</strong></p>
<p>I do not want the secure branch of my webserver directory tree to be part of my &#8220;insecure&#8221; branch that serves unencrypted files. My normal web root directory is <tt>/var/www/</tt> .  The document root for the  secure web server will be located at <tt>/var/www/SSL</tt>.</p>
<pre>[root]# <strong>mkdir /var/www/SSL</strong>
[root]# <strong>chmod 0775 /var/www/SSL</strong>
[root]# <strong>cd /var/www/SSL</strong>
[root]# <strong>mkdir Passneeded</strong><strong>
</strong></pre>
<p>For testing purposes, create a simple HTML file in /var/www/SSL to print &#8220;Apache rocks with SSL&#8221; <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><strong>Step 4: Configure the Apache web server</strong></p>
<p>Create a file, let&#8217;s say <em>https.mycompany.com</em> in /etc/apache2/sites-enabled/ to define your HTTPS virtualhost and include the following lines.</p>
<pre>NameVirtualHost mycompany.com:443
&lt;VirtualHost mycompany.com:443&gt;

DocumentRoot "/var/www/SSL"

# Note that the FQDN and server hostname must go here - clients will not be able to connect, otherwise!
ServerName mars.mycompany.com:443
ServerAdmin webmaster@mycompany.com

#Turning-on the SSL engine
SSLEngine On

# Here, I am allowing only "high" and "medium" security key lengths.
SSLCipherSuite HIGH:MEDIUM

# Here I am allowing SSLv3 and TLSv1, I am NOT allowing the old SSLv2.
SSLProtocol all -SSLv2

#   Server Certificate:
SSLCertificateFile /etc/apache2/ssl.crt/server.crt

#   Server Private Key:
SSLCertificateKeyFile /etc/apache2/ssl.key/server.key

#   Server Certificate Chain:
SSLCertificateChainFile /etc/apache2/ssl.crt/my-ca.crt

#   Certificate Authority (CA):
SSLCACertificateFile /etc/apache2/ssl.crt/my-ca.crt

# This is needed so that you can use auto-indexing for some directories in the
# /var/www/SSL directory branch.  This can be handy if you would like to have
# a list of sensitive files for people to download.
&lt;Directory "/var/www/SSL"&gt;
        Options Indexes
        AllowOverride None
        Allow from from all
        Order allow,deny
&lt;/Directory&gt;</pre>
<p>Also you have to tell Apache, for all HTTPS requests use the port 443. For that append the following lines to <em>/etc/apache2/ports.conf</em></p>
<pre>&lt;IfModule mod_ssl.c&gt;
    Listen "443"
&lt;/IfModule&gt;</pre>
<p><strong>Step 5: Start the web server and test</strong></p>
<p>Run the following commands to start the the Apache web server:</p>
<pre>[root]# <strong>/etc/init.d/apache2 start
Starting web server: apache2.
</strong>Server mycompany.com:443 (RSA)
Enter pass phrase:<strong>
</strong></pre>
<p>Note that you will have to enter the password for your server key in order to start the server. You will also have to do this during boot if you have httpd configured to start automatically.</p>
<p>Make sure that the web server is now listening on the SSL/TLS port, TCP port 443:</p>
<pre>[root]# <strong>netstat -tna</strong>
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:443             0.0.0.0:*               LISTEN</pre>
<p>In order to test that your SSL/TLS web server is running, you will now need to connect to it with a browser. The URL you use should be <tt>https://mycompany.com</tt>. You will probably get a warning prompt about the Certificate Authority (CA) being unknown. You can view the certificate properties, which will look familiar because you created the cert yourself. You can save the cert in your browser, or import the <tt>my-ca.crt</tt> file into your browser as a new CA.  How you do this will depend  on which browser you are using.</p>
<p><strong>Step 6: Require simple username/password auth for one of the directories:</strong></p>
<p>We want to require a valid username and password for the <tt>/var/www/SSL/Passneeded</tt> directory. The username and password will be encrypted in transit as part of the TCP stream. We will need to setup the access control directives, as well as use the <tt>htpasswd</tt> command to add the username/password  pairs.</p>
<pre>[root]# <strong>htpasswd -c -m /etc/apache2/.htpasswd test_user1</strong>
New password:
Re-type new password:
Adding password for user test_user1
[root]# <strong>htpasswd -m /etc/apache2/.htpasswd test_user2</strong>
New password:
Re-type new password:
Adding password for user test_user2

[root]# <strong>chown apache.root /etc/apache2/.htpasswd</strong>
[root]# <strong>chmod 0460 /etc/apache2/.htpasswd</strong></pre>
<p>Now, we need to tell Apache to require a username/password to access the <tt>Passneeded</tt> directory.  Here is  what we will add to <em><tt>/etc/apache2/sites-enabled/https.mycompany.com</tt></em> file:</p>
<pre>&lt;Directory "/var/www/SSL/Passneeded"&gt;
	AuthType Basic
	AuthName "Username and Password Required"
	AuthUserFile /etc/apache2/.htpasswd
	Require valid-user
&lt;/Directory&gt;</pre>
<p>Now, restart the webserver with <tt>/etc/init.d/apache2 restart</tt>.  When you try to access the  <tt>Passneeded</tt> directory from a web browser, you should be prompted for a username and password. If you enter incorrect information, you should be denied access.</p>
<p><strong>Step 7: Change the TCP port that Apache SSL/TLS listens on:</strong></p>
<p>Since this is a private, special-purpose secure web server, you may want to change the TCP port from 443 to something else. This will make it just a little more difficult for crackers to locate via automated network scans. For this excercise, we will change the port to TCP 444 by editing the <tt>ports.conf</tt> configuration file and <em><tt>/etc/apache2/sites-enabled/https.mycompany.com</tt></em>.  Make the following changes to the <tt>ports.conf</tt>:</p>
<pre>&lt;IfModule mod_ssl.c&gt;
    Listen "444"
&lt;/IfModule&gt;</pre>
<p>And make the following changes in <em><tt>/etc/apache2/sites-enabled/https.mycompany.com</tt></em>:</p>
<pre>NameVirtualHost mycompany.com:444
&lt;VirtualHost mycompany.com:444&gt;</pre>
<p>Now, restart Apache and look at the listening ports:</p>
<pre>[root]# <strong>/etc/init.d/apache2 restart</strong>

[root]# <strong>netstat -tna</strong>
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:444             0.0.0.0:*               LISTEN</pre>
<p>Now, you should be able to connect to the server with this URL:</p>
<p><tt>https://mycompany.com:444</tt></p>
<p><strong>Web Server Key Password:</strong></p>
<p>You have probably noticed by now that every time you restart Apache or boot your server, you are forced to enter the password for the server key. This is a security measure, but it can be inconvenient. If you would like to make an <em>insecure</em> server key that will allow Apache to start automatically  at boot time, then there is a way to do this. The choice is yours&#8230;</p>
<p>Here is how you do it:</p>
<pre>[root]# <strong>cd /etc/apache2/ssl.key</strong>
[root]# <strong>cp server.key server.key.orig</strong>

[root]# <strong>openssl rsa -in server.key.orig -out server.key</strong>

[root]# <strong>chmod 0400 server*
</strong></pre>
<p>Now, you should be able to restart Apache or boot your server without having to input the password.   <span style="color:#ff0000;"><strong>This may also be a very good time to copy all the keys and certificates that you made to floppy or CD.</strong></span> You can imagine what a pain it would be if you lost all of your keys and certs due to a disk failure. You may even want to make paper copies of the PEM encoded certificates and keys, which use ASCII text. Lock them in a secure place, along with any passwords.</p>
<p><strong>Conclusion/Final Comments</strong></p>
<p>As you can see, setting up a secure web server for some specific function is not that difficult. All the tools are included with a standard GNU/Linux distribution. OpenSSL is a fantastic Open Source toolkit that can be used in a number of applications. For example, you can use it to run files through different hashing functions, handle S/MIME encrypted mail, or encrypt &amp; decrypt files.</p>
<p>In order to use Apache as a high-volume e-commerce server with SSL/TLS, you will probably need to do more configuration and hardware tuning. You may need to buy and configure a hardware crypto accelerator card. You will almost certainly want to purchase a &#8220;real&#8221; server certificate signed by Entrust, Thawte, or one of the other root-level CAs.</p>
<p>In any event, you now have a good feel for all the pieces, parts, and protocols that make it work!</p>
<p><strong>Resources</strong></p>
<ul>
<li><a href="http://httpd.apache.org/docs-2.0/">Apache 2.0 Documentation</a></li>
<li><a href="http://www.modssl.org/">mod_ssl home page</a></li>
<li><a href="http://www.openssl.org/">OpenSSL home page</a></li>
<li><a href="http://www.ietf.org/html.charters/tls-charter.html">IETF TLS Charter</a></li>
<li>The following man pages:
<ul>
<li>man openssl</li>
<li>man genrsa</li>
<li>man req</li>
<li>man x509</li>
<li>man pkcs12</li>
<li>man htpasswd</li>
</ul>
</li>
</ul>
<p><iframe src='http://digg.com/api/diggthis.php?u=http%3A%2F%2Fdigg.com%2Flinux_unix%2FConfigure_Apache2_with_SSL' height='82' width='55' frameborder='0' scrolling='no' style='float: right; margin-left: 10px; margin-bottom: 5px; padding: 4px 0 2px 4px; background: #fff;'></iframe></p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/saguide.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/saguide.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/saguide.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/saguide.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/saguide.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/saguide.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/saguide.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/saguide.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/saguide.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/saguide.wordpress.com/16/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=saguide.wordpress.com&blog=5170978&post=16&subd=saguide&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://saguide.wordpress.com/2008/10/14/configure-apache2-with-ssl/feed/</wfw:commentRss>
		<slash:comments>1</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>