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

<channel>
	<title>Narnio&#187; authentication</title>
	<atom:link href="http://www.narnio.com/tag/authentication/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.narnio.com</link>
	<description>A day in the life of a software engineer</description>
	<lastBuildDate>Sat, 04 Feb 2012 18:31:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2</generator>
		<item>
		<title>Setting up a mailserver, continued</title>
		<link>http://www.narnio.com/2008/12/15/setting-up-a-mailserver-continued/</link>
		<comments>http://www.narnio.com/2008/12/15/setting-up-a-mailserver-continued/#comments</comments>
		<pubDate>Mon, 15 Dec 2008 19:35:08 +0000</pubDate>
		<dc:creator>Jongerius</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[authentication]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[dovecot]]></category>
		<category><![CDATA[mailserver]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[postfix]]></category>
		<category><![CDATA[smtp]]></category>
		<category><![CDATA[spamassassin]]></category>
		<category><![CDATA[tools]]></category>
		<category><![CDATA[work]]></category>

		<guid isPermaLink="false">http://www.narnio.com/?p=255</guid>
		<description><![CDATA[In my last article on how to setup a basic mail server in debian using postfix and dovecot, I am now continueing on how to setup some basic spam filters. The reason to split this up, well I was stupid and assumed I wouldn&#8217;t need a spam filter yet. But I forgot that I also [...]]]></description>
			<content:encoded><![CDATA[<p>In my last article on how to <a  title="First article on setting up a basic Debian mail server" href="http://www.narnio.com/2008/12/08/debian-setting-up-a-postfix-and-dovecot-mail-server/">setup a basic mail server in debian using postfix and dovecot</a>, I am now continueing on how to setup some basic spam filters. The reason to split this up, well I was stupid and assumed I wouldn&#8217;t need a spam filter yet. But I forgot that I also moved one domain to my new mail server that got 200 spam messages a day.</p>
<p>So now to repair my mistake I am adding the following features to my already existing mail server. To find out how to setup the  mail server itself read my earlier article.</p>
<ul>
<li>Use spamassassin to mark spam in the header</li>
<li>Change the mail delivery to dovecot LDA, this is needed for step 3</li>
<li>Automatically move marked e-mails to the spam folder of the user</li>
</ul>
<p>Sounds easy right. Well it should be <img src='http://www.narnio.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> .</p>
<p><span id="more-255"></span></p>
<h2>Install spamassassin and set it up in postfix</h2>
<p>The first step we will take is installing and setting up the spamassassin tool. First lets install it with the default options from Debian by running:</p>
<p><code><br />
apt-get install spamassassin<br />
useradd -g spamd -s /bin/false -m -d /home/spamassassin spamd</code></p>
<p>Next we setup the basics of spamassassin configuration, the file called /etc/spamassassin/local.cf</p>
<p><code>report_safe        0<br />
required_score     2.0</code><br />
<code>use_bayes          1<br />
bayes_auto_learn   1<br />
use_bayes_rules    1</code></p>
<p><code># Some basic configuration<br />
score DCC_CHECK 4.000<br />
score SPF_FAIL 10.000<br />
score SPF_HELO_FAIL 10.000<br />
score RAZOR2_CHECK 2.500<br />
score BAYES_99 4.300<br />
score BAYES_95 3.500<br />
score BAYES_80 3.000</code></p>
<p><code># Headers to be added for all scanned messages<br />
add_header all Status _YESNO_, score=_SCORE_ required=_REQD_ tests=_TESTS_ autolearn=_AUTOLEARN_ version=_VERSION_<br />
add_header all Level _STARS(*)_<br />
add_header all Checker-Version SpamAssassin _VERSION_ (_SUBVERSION_) on _HOSTNAME_</code></p>
<p>So what we&#8217;ve done so far is set spamassassin up to automatically learn from mail it receives and to mark anything with a bayes score over 2 as spam. But we still need to integrate it into postfix to get it to work. Add the following to the postfix configuration (/etc/postfix/master.cf):</p>
<p><code>spamassassin unix -     n       n       -       -       pipe<br />
 user=spamd argv=/usr/bin/spamc -f -e<br />
 /usr/sbin/sendmail -oi -f ${sender} ${recipient}</code></p>
<p>You will also need to change the smtp line in the same file to the following, this will set up spamassassin as a pre delivery filter:</p>
<p><code>smtp      inet  n     -     -     -     -     smtpd -o content_filter=spamassassin</code></p>
<p>This will add the spamassassin service as a unix service through a pipe connection. Sounds complicated but it&#8217;s really easy it basically uses a binary file to comunicate between postfix and spamassassin. Make sure the user <em>spamd</em> exists and create the folder <em>/usr/bin/spamc</em> with full access to the spamd user. Also edit the file spamassassin to the following:</p>
<p><code># /etc/default/spamassassin<br />
# Change to one to enable spamd<br />
ENABLED=1</code></p>
<p><code># SpamAssassin uses a preforking model, so be careful! You need to<br />
# make sure --max-children is not set to anything higher than 5,<br />
# unless you know what you're doing.<br />
SAHOME="/var/lib/spamassassin/"<br />
OPTIONS="--create-prefs --max-children 5 --username spamd --helper-home-dir ${SAHOME} -s ${SAHOME}spamd.log"<br />
PIDFILE="${SAHOME}spamd.pid"<br />
CRON=0</code></p>
<p>Make sure to create the directory <em>/var/lib/spamassassin</em> and give spamd full access right to it, otherwise the service might not run properly. Spamassassin is now setup and will start scanning your e-mail. So if all you are interested in is the header being changed to indicate if a message is spam then you are done. If you also wish yo move it to a different folder then continue reading.</p>
<h2>Settup Dovecot as LDA (Local Delivery Agent)</h2>
<p>Next step is setting up dovecot as the default LDA for postfix. This is needed to let dovecot filter messages into the proper locations. First setup the connection to the between postfix and dovecot by adding the following to the <em>/etc/postfix/master.cf</em>:</p>
<p><code>dovecot   unix  -       n       n       -       -       pipe<br />
 flags=DRhu user=dovecot:dovecot<br />
 argv=/usr/lib/dovecot/deliver -f ${sender} -d ${recipient}</code></p>
<p>Please note that we now need to keep track of the fact that dovecot will be the user that is running this part of the mail server. So every file needed, log or configuration and mailboxes related, need to be owned by dovecot:dovecot. I have had issues with files having the wrong owner so it is important! Before activating the postfix connection lets configure dovecot for LDA by editing the <em>/etc/dovecot/dovecot.conf</em> file. Add the following piece of code in the group auth default &gt;&gt; socket listen:</p>
<p><code>        master {<br />
          path = /var/run/dovecot/auth-master<br />
          user = dovecot<br />
          group= ssl-cert<br />
          mode = 0600<br />
        }<br />
</code></p>
<p>This will setup the authentication service that dovecot will use for delivering the e-mail to the correct user and authenticating users. Also add the following at the bottom of the file to configure the LDA of dovecot:</p>
<p><code>protocol lda {<br />
  mail_plugins = cmusieve<br />
  sieve_global_path = /etc/dovecot/globalsieverc/global.sieve<br />
  log_path = /var/log/dovecot-delivery_log<br />
  postmaster_address = <a  href="mailto:noreply@domain.com">noreply@domain.com</a><br />
}</code></p>
<p><code>plugin {<br />
 sieve = /etc/dovecot/globalsieverc/global.sieve<br />
}</code></p>
<p>Again make sure that the user dovecot has full access to both the logfile and the global sieve directory (which you will need to make) <img src='http://www.narnio.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> . The plugin group is just for safety. I don&#8217;t know if it is needed but it doesn&#8217;t break anything. Also check the dovecot-mysql.conf that you made earlier to make sure that the uid and gid are those of the dovecot user. You can find this out by running:</p>
<p><code>:&gt; id dovecot</code></p>
<p>If this is all setup in dovecot restart it by running:</p>
<p><code>:&gt;/etc/init.d/dovecot force-reload</code></p>
<p>Now it is time to wrap things up and activate dovecot as the LDA for postfix, edit the file /etc/postfix/main.cf and change the virtual_transport from virtual to dovecot. Last but not least is creating the globe.sieve file.</p>
<p><code>:&gt; vi /etc/dovecot/globalsieverc/global.sieve</code></p>
<p><code>require ["fileinto"];<br />
if anyof (<br />
    header :contains ["X-Spam-Flag"] "Yes"<br />
) {<br />
    fileinto "Spam"; stop;<br />
}</code></p>
<p>Now restart postfix and send yourself a test mail. If everything is setup correctly it should be delivered to your mailbox. If not then first check &#8216;/var/log/mail.info&#8217; to gather some information as to what is going on. If this indicates a delivery was attempted but it failed then check &#8216;/var/log/dovecot-delivery_log&#8217; to find out more.</p>
<p>I hope you have fun using your spam free mail server. If you have any issues let me know, but please include snippets from the log as this will help me help you <img src='http://www.narnio.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<hr/>Copyright &copy; 2012 <strong><a  href="http://www.narnio.com">Narnio</a></strong>. This Feed is for personal non-commercial use only. If you are not reading this material in your news aggregator, the site you are looking at is guilty of copyright infringement. Please contact legal@jong-soft.com so we can take legal action immediately.]]></content:encoded>
			<wfw:commentRss>http://www.narnio.com/2008/12/15/setting-up-a-mailserver-continued/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Debian Setting up a Postfix and Dovecot mail server</title>
		<link>http://www.narnio.com/2008/12/08/debian-setting-up-a-postfix-and-dovecot-mail-server/</link>
		<comments>http://www.narnio.com/2008/12/08/debian-setting-up-a-postfix-and-dovecot-mail-server/#comments</comments>
		<pubDate>Mon, 08 Dec 2008 18:18:56 +0000</pubDate>
		<dc:creator>Jongerius</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Internet]]></category>
		<category><![CDATA[Webdevelopment]]></category>
		<category><![CDATA[authentication]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[dovecot]]></category>
		<category><![CDATA[imap]]></category>
		<category><![CDATA[mailserver]]></category>
		<category><![CDATA[postfix]]></category>
		<category><![CDATA[smtp]]></category>

		<guid isPermaLink="false">http://www.narnio.com/?p=240</guid>
		<description><![CDATA[Ok over the weekend I spent some time to finally set up my personal mail server on the VPS system I have. I had been planning this for some time, and made several unsuccessful attempts. But this weekend after spending some hard time on it I finally got it working. My setup is as follows: [...]]]></description>
			<content:encoded><![CDATA[<p>Ok over the weekend I spent some time to finally set up my personal mail server on the VPS system I have. I had been planning this for some time, and made several unsuccessful attempts. But this weekend after spending some hard time on it I finally got it working.</p>
<p>My setup is as follows:</p>
<ul>
<li>Postfix as a SMTP service</li>
<li>Dovecot as the IMAPS service and authentication service</li>
<li>MySQL as a storage location indicating the virtual email boxes and domains</li>
<li>PostfixAdmin as a package to manage the virtual domains and boxes</li>
</ul>
<p><span id="more-240"></span></p>
<h2>Installing the whole thing</h2>
<p>The first thing you might wanna do is install the needed services and applications on your Debian machine. You can install everything using:</p>
<p><code>apt-get install dovecot-common dovecot-imaps postfix postfix-mysql</code></p>
<p>At this point I am asuming you already have MySQL installed and configured. If not then you should do so, but I won&#8217;t include that in this tutorial. The PostfixAdmin needs to be downloaded from <a  href="http://sourceforge.net/projects/postfixadmin/">http://sourceforge.net/projects/postfixadmin/</a>. You will need to setup this somewhere on the webserver site, either in an already configured apache directory or by configuring a new one.</p>
<h2>Setting up everything in MySQL</h2>
<p>After everything is installed you will need to prepare everything in MySQL. Connect to your machine and run the following code to generate a database and tables in that database:</p>
<p><code>create database postfix;<br />
</code><code>grant all on postfix.* to postfix identified by 'postfix';<br />
grant all on postfix.* to postfixadmin identified by 'postfixadmin';<br />
set password for postfixadmin = old_password('postfixadmin');</code></p>
<p>This will setup the basic stuff for postfix and postfix admin to work. Next step is setting up the data for postfix. First configure the postfixAdmin plugin by setting some of the settings in &#8216;config.inc.php&#8217;.</p>
<h2>Setup Postfix configuration</h2>
<p>The next step is configuring Postfix to enable it to sent mails, use the MySQL database and login using the Dovecot application. The latter you will setup in a later stage. First open the <em>&#8216;/etc/postfix/main.cf&#8217;</em> file and change the entire content to something like:<br />
<code><br />
queue_directory = /var/spool/postfix<br />
command_directory = /usr/sbin<br />
daemon_directory = /usr/lib/postfix<br />
mail_owner = postfix</code><code>## Host name given by ISP<br />
myhostname = &lt;isp hostname&gt;<br />
mydomain   = &lt;domainname&gt;<br />
unknown_local_recipient_reject_code = 550<br />
debug_peer_level = 1</code></p>
<p><code># Virtual domain administration MySQL<br />
virtual_alias_maps      = mysql:/etc/postfix/mysql_virtual_alias_maps.cf<br />
virtual_gid_maps        = static:104<br />
virtual_mailbox_base    = /usr/postfix/<br />
virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf<br />
virtual_mailbox_limit   = 51200000<br />
virtual_mailbox_maps    = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf<br />
virtual_minimum_uid     = 104<br />
virtual_transport       = virtual<br />
virtual_uid_maps        = static:104</code></p>
<p><code># The settings for the SASQL authentication using the autdaemon.<br />
smtpd_recipient_restrictions =<br />
   permit_mynetworks,<br />
   permit_sasl_authenticated,<br />
   reject_unauth_destination,<br />
   reject_unauth_pipelining,<br />
   reject_invalid_hostname,<br />
   reject_rbl_client list.dsbl.org,<br />
   reject_rbl_client sbl-xbl.spamhaus.org<br />
smtpd_sasl_auth_enable           = yes<br />
broken_sasl_auth_clients         = yes</code></p>
<p><code># Setup authentication using Dovecot<br />
smtpd_sasl_type = dovecot<br />
smtpd_sasl_path = private/auth<br />
</code><br />
In the above configuration you need to manually change the domain name to your primary domain and the ISP domain to the name given by your ISP. Another thing you must change is the number <em>104</em> this should be the UID of the <em>postfix</em> user on your system. You can find out what the UID is by running: </p>
<p> <code>id postfix</code></p>
<h2>Setting up the Postfix SQL files</h2>
<p>The last step in the postfix configuration is setting up the SQL files that instruct postfix on how to load the data from the MySQL database. Run the commands as instructed below.</p>
<p><code><strong>:&gt; vi /etc/postfix/mysql_virtual_mailbox_maps.cf</strong></code></p>
<p><code>user     = postfix<br />
password = &lt;password&gt;<br />
hosts    = &lt;ipaddress&gt;<br />
dbname   = postfix<br />
query    = SELECT maildir FROM mailbox WHERE username='%s' AND active = 1</code></p>
<p><code><strong>:&gt; vi /etc/postfix/mysql_virtual_domains_maps.cf</strong></code></p>
<p><code>user     = postfix<br />
password = &lt;password&gt;<br />
hosts    = &lt;ipaddress&gt;<br />
dbname   = postfix<br />
query    = SELECT domain FROM domain WHERE domain='%s'</code></p>
<p><code><strong>:&gt; vi /etc/postfix/mysql_virtual_alias_maps.cf</strong></code></p>
<p><code>user     = postfix<br />
password = &lt;password&gt;<br />
hosts  = &lt;ipaddress&gt;<br />
dbname = postfix<br />
query  = SELECT goto FROM alias WHERE address='%s' AND active = 1</code> </p>
<p>Change the password and the host name to the ones as configured in your MySQL server. If everything went correct your postfix should be up and running by now. Please note that the logon when sending mail does not work yet as dovecot has not yet been configured.</p>
<h2>Configuring Dovecot</h2>
<p>Your last step should be easy. Edit the dovecot.conf file into the following.</p>
<p><code>protocols = imaps<br />
log_path  = /var/log/dovecot_log<br />
log_timestamp = "%Y-%m-%d %H:%M:%S "</code></p>
<p><code>default_mail_env      = maildir:/usr/postfix/%d/%n<br />
mail_privileged_group = mail<br />
first_valid_uid       = 100</code></p>
<p><code>protocol imap {<br />
  imap_client_workarounds = outlook-idle<br />
}</code></p>
<p><code>##<br />
## Authentication processes<br />
##<br />
auth_username_chars = abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890.-_@<br />
auth default {<br />
  mechanisms = plain login<br />
  userdb sql {<br />
    args=/etc/dovecot/dovecot-mysql.conf<br />
  }<br />
  passdb sql {<br />
    args=/etc/dovecot/dovecot-mysql.conf<br />
  }<br />
  socket listen {<br />
    client {<br />
      path = /var/spool/postfix/private/auth<br />
      mode = 0660<br />
      user = postfix<br />
      group = postfix<br />
    }<br />
  }<br />
}<br />
</code></p>
<p>This simple configuration will enable dovecot to use IMAPS (you could also add POP or IMAP). The <em>auth default</em> group defines how to authenticate the user. In our case this is using the MySQL database to locate passwords and the directory of the user. We also define a socket in this group that indicates a location where Dovecot should offer the authentication service for other application, being Postfix in our case.</p>
<p>The last step for the dovecot setup is creating the query to find the data. Run the following command and then paste the code below:</p>
<p><code><strong>:&gt; vi /etc/dovecot/dovecot-mysql.conf</strong></code></p>
<p><code>driver = mysql<br />
connect = host=&lt;host&gt; dbname=postfix user=postfix password=&lt;password&gt;<br />
default_pass_scheme = CRYPT<br />
password_query = SELECT password FROM mailbox WHERE username = '%u'<br />
user_query = SELECT maildir, &lt;uid&gt; AS uid, &lt;uid&gt; AS gid FROM mailbox WHERE username = '%u'</code></p>
<p>You should change the host, password and UID. The UID is the one you previously obtained for postfix.</p>
<p>If everything is done correctly you can start adding domains, mailboxes and aliasses using PostfixAdmin. As well as starting the Postfix and dovecot service. You can do this by running:</p>
<p><code><strong>:&gt; /etc/init.d/dovecot start<br />
:&gt; postfix start</strong></code></p>
<p>And you&#8217;re all done. Congratulations you now have a mail service running on you Debian machine. If you have any difficulties please let me know and please post a snippet of the <em>&#8216;/var/log/mail.info&#8217;</em> to help me understand what&#8217;s going on. Trust me that I&#8217;ve probably seen most of the errors that you can encounter come by.</p>
<hr/>Copyright &copy; 2012 <strong><a  href="http://www.narnio.com">Narnio</a></strong>. This Feed is for personal non-commercial use only. If you are not reading this material in your news aggregator, the site you are looking at is guilty of copyright infringement. Please contact legal@jong-soft.com so we can take legal action immediately.]]></content:encoded>
			<wfw:commentRss>http://www.narnio.com/2008/12/08/debian-setting-up-a-postfix-and-dovecot-mail-server/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>SSH setup login using certificates</title>
		<link>http://www.narnio.com/2008/11/18/ssh-setup-login-using-certificates/</link>
		<comments>http://www.narnio.com/2008/11/18/ssh-setup-login-using-certificates/#comments</comments>
		<pubDate>Tue, 18 Nov 2008 11:24:16 +0000</pubDate>
		<dc:creator>Jongerius</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Internet]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Webdevelopment]]></category>
		<category><![CDATA[authentication]]></category>
		<category><![CDATA[certificate]]></category>
		<category><![CDATA[SSH]]></category>

		<guid isPermaLink="false">http://www.narnio.com/?p=228</guid>
		<description><![CDATA[Once you are running a linux server you can choose to do the login by username and password authentication or by certificate authentication. Personally I always choose for the latter as it is more difficult to intercept or hack in to. Setting up certificate authentication is really simple. Just login to the machine as you [...]]]></description>
			<content:encoded><![CDATA[<p>Once you are running a linux server you can choose to do the login by username and password authentication or by certificate authentication. Personally I always choose for the latter as it is more difficult to intercept or hack in to.</p>
<p>Setting up certificate authentication is really simple. Just login to the machine as you would normally. Change to the user you are setting-up a certificate for and enter:</p>
<p><code>ssh-keygen -t rsa</code></p>
<p>You will be prompted for a password twice. After this is completed two files will be generated. One being the public file and one being the prive file. You need to download the private file from the server and store it somewhere safe. The public key needs to be copied to:</p>
<p><code> ~/.ssh/authorized_keys</code></p>
<p>After this you will be able to login to the server using your username and the private certificate. Please note that for Putty you will need to import the generated private key into puttygen and export it into a new private key. This is because Putty does not support the SSH generated private key.</p>
<p><strong>Update: </strong>fixed the name of the keyfile to actually make it work, thanks for that neosam.</p>
<hr/>Copyright &copy; 2012 <strong><a  href="http://www.narnio.com">Narnio</a></strong>. This Feed is for personal non-commercial use only. If you are not reading this material in your news aggregator, the site you are looking at is guilty of copyright infringement. Please contact legal@jong-soft.com so we can take legal action immediately.]]></content:encoded>
			<wfw:commentRss>http://www.narnio.com/2008/11/18/ssh-setup-login-using-certificates/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

