<?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>Climens&#039; Codelog &#187; Linux</title>
	<atom:link href="http://codelog.climens.net/category/linux/feed/" rel="self" type="application/rss+xml" />
	<link>http://codelog.climens.net</link>
	<description>Development, productivity, blogging, technology, life in the trenches...</description>
	<lastBuildDate>Tue, 20 Dec 2011 22:41:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Using fail2ban with nginx in Debian</title>
		<link>http://codelog.climens.net/2011/02/13/using-fail2ban-with-nginx-in-debian/</link>
		<comments>http://codelog.climens.net/2011/02/13/using-fail2ban-with-nginx-in-debian/#comments</comments>
		<pubDate>Sun, 13 Feb 2011 13:03:16 +0000</pubDate>
		<dc:creator>climens</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Seguridad]]></category>
		<category><![CDATA[fail2ban]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[spam]]></category>

		<guid isPermaLink="false">http://codelog.climens.net/?p=336</guid>
		<description><![CDATA[Taking a look at the logwatch mails I see a common pattern of attacks, coming from China and trying to find details of my server configuration, which is something I dont like. Looking around I found fail2ban which is a tool that does som regex matches on the server logs (sshd, httpd, authd, &#8230;) and [...]]]></description>
			<content:encoded><![CDATA[<div class="socialize-in-content" style="float:left;"><div class="socialize-in-button socialize-in-button-left"><g:plusone size="tall" href="http://codelog.climens.net/2011/02/13/using-fail2ban-with-nginx-in-debian/"></g:plusone></div><div class="socialize-in-button socialize-in-button-left"><a href="http://twitter.com/share" class="twitter-share-button" data-url="http://codelog.climens.net/2011/02/13/using-fail2ban-with-nginx-in-debian/" data-text="Using fail2ban with nginx in Debian" data-count="vertical" data-via="socializeWP" ><!--Tweetter--></a></div><div class="socialize-in-button socialize-in-button-left"><iframe src="http://www.facebook.com/plugins/like.php?href=http://codelog.climens.net/2011/02/13/using-fail2ban-with-nginx-in-debian/&amp;layout=box_count&amp;show_faces=true&amp;width=80&amp;action=like&amp;font=arial&amp;colorscheme=light&amp;height=65" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:80px !important; height:65px;" allowTransparency="true"></iframe></div></div><p>Taking a look at the logwatch mails I see a common pattern of attacks, coming from China and trying to find details of my server configuration, which is something I dont like.</p>
<p>Looking around I found <a href="http://www.fail2ban.org/">fail2ban</a> which is a tool that does som regex matches on the server logs (sshd, httpd, authd, &#8230;) and takes proper actions, like banning the offending IP.</p>
<p>I then installed fail2ban in my Debian box:</p>
<pre class="brush: plain; title: ; notranslate">
&gt; apt-get install fail2ban
</pre>
<p>Then, I took a look at /etc/fail2ban/jail.conf and found some entries for Apache but none for <a href="http://nginx.org/">nginx</a>, my server of choice, so I decided to create a <strong>jail.local</strong> to add some nginx stuff (this is recommended in Debian to allow hassle-free upgrades).</p>
<p>I started copying the Apache sections of the default fail2ban as the log files in my case use the same format that allows me to use Awstats easily. Then, I modified my log routes to point to the nginx ones and using Apache rules, if they don&#8217;t work I&#8217;ll tune them later.</p>
<pre class="brush: plain; title: ; notranslate">
[nginx]

enabled = true
port    = http,https
filter  = apache-auth
logpath = /var/log/nginx*/*error.log
maxretry = 6

[nginx-noscript]

enabled = false
port    = http,https
filter  = apache-noscript
logpath = /var/log/nginx*/*error.log
maxretry = 6

[nginx-overflows]

enabled = false
port    = http,https
filter  = apache-overflows
logpath = /var/log/nginx*/*error.log
maxretry = 2
</pre>
<p>Although this is ok, the bots I see don&#8217;t leave a trace in error.log but in access.log so I took a look at the filter.d folder where an interesting apache-badbots.conf was present. Then, I found the default fail2ban documentation in /usr/share/doc/fail2ban where there&#8217;s an usage example of the badbots script. I added I to my jail.local:</p>
<pre class="brush: plain; title: ; notranslate">
[apache-badbots]

enabled  = true
port    = http,http
filter   = apache-badbots
logpath  = /var/log/nginx*/*access.log
bantime  = 172800
maxretry = 1
</pre>
<p>Finally, I added this to the top of the file, to send mails to myself when a rule matches and a host is banned.</p>
<pre class="brush: plain; title: ; notranslate">
[DEFAULT]

action = %(action_mwl)s
</pre>
<p>Finally, restart the service and start receiving mails:</p>
<pre class="brush: plain; title: ; notranslate">
&gt; sudo /etc/init.d/fail2ban restart
</pre>
<p>I&#8217;m sure this will need further adjustments, but it&#8217;s a beginning in my bot fighting war. I&#8217;ll make some updates as I find interesting results.</p>
]]></content:encoded>
			<wfw:commentRss>http://codelog.climens.net/2011/02/13/using-fail2ban-with-nginx-in-debian/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Using Dreamhost backup account with rsync</title>
		<link>http://codelog.climens.net/2008/12/03/using-dreamhost-backup-account-with-rsync/</link>
		<comments>http://codelog.climens.net/2008/12/03/using-dreamhost-backup-account-with-rsync/#comments</comments>
		<pubDate>Wed, 03 Dec 2008 12:06:09 +0000</pubDate>
		<dc:creator>climens</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[dreamhost]]></category>
		<category><![CDATA[rsync]]></category>

		<guid isPermaLink="false">http://codelog.climens.net/?p=110</guid>
		<description><![CDATA[This summer Dreamhost launched their 50Gb backup account which was great news but unfortunately they only offered FTP access. In the October newsletter they announced rsync and SCP support for the backup user using RSSH and I will now show you how to set up an automatic script to back your valuable data up. That [...]]]></description>
			<content:encoded><![CDATA[<div class="socialize-in-content" style="float:left;"><div class="socialize-in-button socialize-in-button-left"><g:plusone size="tall" href="http://codelog.climens.net/2008/12/03/using-dreamhost-backup-account-with-rsync/"></g:plusone></div><div class="socialize-in-button socialize-in-button-left"><a href="http://twitter.com/share" class="twitter-share-button" data-url="http://codelog.climens.net/2008/12/03/using-dreamhost-backup-account-with-rsync/" data-text="Using Dreamhost backup account with rsync" data-count="vertical" data-via="socializeWP" ><!--Tweetter--></a></div><div class="socialize-in-button socialize-in-button-left"><iframe src="http://www.facebook.com/plugins/like.php?href=http://codelog.climens.net/2008/12/03/using-dreamhost-backup-account-with-rsync/&amp;layout=box_count&amp;show_faces=true&amp;width=80&amp;action=like&amp;font=arial&amp;colorscheme=light&amp;height=65" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:80px !important; height:65px;" allowTransparency="true"></iframe></div></div><p><a href="http://www.dreamhost.com/r.cgi?201114"><img class="alignright size-full wp-image-112" style="padding: 10px" src="http://codelog.climens.net/files/2008/12/dreamhost.png" alt="" width="156" height="33" /></a>This summer Dreamhost <a href="http://wiki.dreamhost.com/V10.08_August_2008">launched their <strong>50Gb backup</strong> account</a> which was great news but unfortunately they only offered FTP access. In the <a href="http://wiki.dreamhost.com/V10.10_October_2008">October newsletter</a> they announced rsync and SCP support for the backup user using <a href="http://www.pizzashack.org/rssh/index.shtml">RSSH</a> and I will now show you how to set up an automatic script to back your valuable data up. That is quite cool, so don&#8217;t hesitate to <a href="http://www.dreamhost.com/r.cgi?201114">sign-up with them</a> and try out this feature.</p>
<p>The first thing is configuring the account for SCP/SFTP/rsync access. Go to the <a href="https://panel.dreamhost.com/index.cgi?tree=users.backup&amp;">Backups User section</a> of the Users menu in the Panel and create a user. They&#8217;ll give you a name and a password and send you an email with all the information. That&#8217;s the only thing you need.</p>
<p>Then, you must create the folder structure to hold your backups in case you don&#8217;t want to have everything on the root folder. The easiest thing is to get a SFTP client. In my case I used <a href="http://winscp.net/">WinSCP</a>, but you can use whatever you want. I created a folder called photos to hold my digital collection.</p>
<p>Now, the trickiest part. If you have a modern Linux distribution or any up to date <em>rsync</em> compilation it&#8217;s very possible that you have version 3.0 or later that implements protocol version 30. To know the version of <em>rsync</em>, just write:</p>
<pre class="brush: plain; title: ; notranslate">
rsync --version
</pre>
<p>In my case, I have &#8220;rsync  version 3.0.3  protocol version 30&#8243;. In that case, if you use <em>rsync</em> as usual, you&#8217;ll get a nice error saying that:</p>
<pre class="brush: plain; title: ; notranslate">
insecure -e option not allowed.
This account is restricted by rssh.
Allowed commands: scp sftp rsync
</pre>
<p>After googling a little, I discovered that protocol 30 sends implicitly an -e command and the installed version in Dreamhost does not like that, because it uses protocol 29. The solution is adding &#8216;&#8211;protocol 29&#8242; to the rsync options.</p>
<p>Then, to make the whole process automatic, you need to avoid <em>rsync</em> asking for a password. That can be easily done following this instructions on <a href="http://blogs.translucentcode.org/mick/archives/000230.html" class="broken_link">passwordless ssh</a>. Note that you can&#8217;t ssh to the remote machine but if you create a new file called <em>authorized_keys</em> locally with the contents of <em>id_dsa.pub</em> and then using the SFTP client upload it to a new folder (if not exists) called <em>.ssh</em> (don&#8217;t forget the dot!). It will work like a charm.</p>
<p>Then, create a script that does the <em>rsync</em> thing. In my case, I have this single instruction, but you can sync as many folders as you want.</p>
<pre class="brush: plain; title: ; notranslate">
rsync -aP --delete --protocol=29 /mnt/photos/* bXXXXXXX@backup.dreamhost.com:photos
</pre>
<p>With this, I tell <em>rsync</em> to use archive mode (-a), which is quite interesting as it preserves timestamps and is recursive, and to store partial information (-P) in case I break the connection. Then I tell <em>rsync</em> to delete the destination files that are not in the source (which can be dangerous if you delete something locally and want to recover it later, so I leave this option up to you). Then to use protocol version 29 (&#8211;protocol 29) as I discussed earlier. Finally, I tell <em>rsync </em>which is the source folder and the destination one, indicating the username and the host.</p>
<p>And that&#8217;s it. If you store this command in a .sh file and put it in the crontab (with crontab -e), you can automatically back up your valuable data to the Dreamhost backup account. My crontab settings are like this:</p>
<pre class="brush: plain; title: ; notranslate">
# m h  dom mon dow   command
0 2 * * * ~/backup.sh &amp;amp;amp;gt; ~/backup.log
</pre>
<p>This will execute the backup script every day at 2 AM, and will store a .log, in case I want to check the results. Note that the first time that you execute the script it may take some time (4 days for me, 18Gb in total) depending on the amount of data to back up, so I recommend you to execute it manually before creating an automatic task.</p>
<p>Finally, I want to remind you that the data stored in that account is not guaranteed by any means by Dreamhost, so don&#8217;t make it your only full trusted source for backup data.</p>
<p>Link | <a href="http://www.dreamhost.com/r.cgi?201114">Dreamhost</a></p>
<p>Note: This is my first post in English, so please forgive my errors, I tried my best. <img src='http://codelog.climens.net/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://codelog.climens.net/2008/12/03/using-dreamhost-backup-account-with-rsync/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
	</channel>
</rss>

