<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
        <title>dev.baeck.at</title>
        <description>dev.baeck.at - Gerald Bäck</description>
        <link>http://dev.baeck.at</link>
        <link>http://dev.baeck.at</link>
        <lastBuildDate>2014-06-08T04:22:16-07:00</lastBuildDate>
        <pubDate>2014-06-08T04:22:16-07:00</pubDate>
        <ttl>1800</ttl>


        <item>
                <title>How to Switch to a german keyboard layout on a Raspberry</title>
                <description>&lt;p&gt;Open up a shell and type&lt;/p&gt;
&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;bash&#39;&gt;  sudo nano /etc/default/keyboard
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;find where it says&lt;/p&gt;
&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;bash&#39;&gt;  &lt;span class=&#39;nv&#39;&gt;XKBLAYOUT&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;=&lt;/span&gt;”gb”
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;change it to:&lt;/p&gt;
&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;bash&#39;&gt;  &lt;span class=&#39;nv&#39;&gt;XKBLAYOUT&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;=&lt;/span&gt;”de”
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</description>
                <link>http://dev.baeck.at/raspberry/2014/05/26/How-To-Switch-to-A-German-Keyboard-Layout-On-a-raspberry</link>
                <guid>http://dev.baeck.at/raspberry/2014/05/26/How-To-Switch-to-A-German-Keyboard-Layout-On-a-raspberry</guid>
                <pubDate>2014-05-26T00:00:00-07:00</pubDate>
        </item>

        <item>
                <title>How to limit Amazon S3 access to one bucket only</title>
                <description>&lt;p&gt;If you want to limit the access of a specific user/group to only one S3 bucket you should use the following IAM policy:&lt;/p&gt;
&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;json&#39;&gt;&lt;span class=&#39;p&#39;&gt;{&lt;/span&gt;
  &lt;span class=&#39;nt&#39;&gt;&amp;quot;Statement&amp;quot;&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;:&lt;/span&gt; &lt;span class=&#39;p&#39;&gt;[&lt;/span&gt;
    &lt;span class=&#39;p&#39;&gt;{&lt;/span&gt;
      &lt;span class=&#39;nt&#39;&gt;&amp;quot;Effect&amp;quot;&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;:&lt;/span&gt; &lt;span class=&#39;s2&#39;&gt;&amp;quot;Allow&amp;quot;&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;,&lt;/span&gt;
      &lt;span class=&#39;nt&#39;&gt;&amp;quot;Action&amp;quot;&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;:&lt;/span&gt; &lt;span class=&#39;p&#39;&gt;[&lt;/span&gt;
        &lt;span class=&#39;s2&#39;&gt;&amp;quot;s3:ListBucket&amp;quot;&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;,&lt;/span&gt;
        &lt;span class=&#39;s2&#39;&gt;&amp;quot;s3:GetBucketLocation&amp;quot;&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;,&lt;/span&gt;
        &lt;span class=&#39;s2&#39;&gt;&amp;quot;s3:ListBucketMultipartUploads&amp;quot;&lt;/span&gt;
      &lt;span class=&#39;p&#39;&gt;],&lt;/span&gt;
      &lt;span class=&#39;nt&#39;&gt;&amp;quot;Resource&amp;quot;&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;:&lt;/span&gt; &lt;span class=&#39;s2&#39;&gt;&amp;quot;arn:aws:s3:::bucketname&amp;quot;&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;,&lt;/span&gt;
      &lt;span class=&#39;nt&#39;&gt;&amp;quot;Condition&amp;quot;&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;:&lt;/span&gt; &lt;span class=&#39;p&#39;&gt;{}&lt;/span&gt;
    &lt;span class=&#39;p&#39;&gt;},&lt;/span&gt;
    &lt;span class=&#39;p&#39;&gt;{&lt;/span&gt;
      &lt;span class=&#39;nt&#39;&gt;&amp;quot;Effect&amp;quot;&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;:&lt;/span&gt; &lt;span class=&#39;s2&#39;&gt;&amp;quot;Allow&amp;quot;&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;,&lt;/span&gt;
      &lt;span class=&#39;nt&#39;&gt;&amp;quot;Action&amp;quot;&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;:&lt;/span&gt; &lt;span class=&#39;p&#39;&gt;[&lt;/span&gt;
        &lt;span class=&#39;s2&#39;&gt;&amp;quot;s3:AbortMultipartUpload&amp;quot;&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;,&lt;/span&gt;
        &lt;span class=&#39;s2&#39;&gt;&amp;quot;s3:DeleteObject&amp;quot;&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;,&lt;/span&gt;
        &lt;span class=&#39;s2&#39;&gt;&amp;quot;s3:DeleteObjectVersion&amp;quot;&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;,&lt;/span&gt;
        &lt;span class=&#39;s2&#39;&gt;&amp;quot;s3:GetObject&amp;quot;&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;,&lt;/span&gt;
        &lt;span class=&#39;s2&#39;&gt;&amp;quot;s3:GetObjectAcl&amp;quot;&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;,&lt;/span&gt;
        &lt;span class=&#39;s2&#39;&gt;&amp;quot;s3:GetObjectVersion&amp;quot;&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;,&lt;/span&gt;
        &lt;span class=&#39;s2&#39;&gt;&amp;quot;s3:GetObjectVersionAcl&amp;quot;&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;,&lt;/span&gt;
        &lt;span class=&#39;s2&#39;&gt;&amp;quot;s3:PutObject&amp;quot;&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;,&lt;/span&gt;
        &lt;span class=&#39;s2&#39;&gt;&amp;quot;s3:PutObjectAcl&amp;quot;&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;,&lt;/span&gt;
        &lt;span class=&#39;s2&#39;&gt;&amp;quot;s3:PutObjectAclVersion&amp;quot;&lt;/span&gt;
      &lt;span class=&#39;p&#39;&gt;],&lt;/span&gt;
      &lt;span class=&#39;nt&#39;&gt;&amp;quot;Resource&amp;quot;&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;:&lt;/span&gt; &lt;span class=&#39;s2&#39;&gt;&amp;quot;arn:aws:s3:::bucketname/*&amp;quot;&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;,&lt;/span&gt;
      &lt;span class=&#39;nt&#39;&gt;&amp;quot;Condition&amp;quot;&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;:&lt;/span&gt; &lt;span class=&#39;p&#39;&gt;{}&lt;/span&gt;
    &lt;span class=&#39;p&#39;&gt;},&lt;/span&gt;
    &lt;span class=&#39;p&#39;&gt;{&lt;/span&gt;
      &lt;span class=&#39;nt&#39;&gt;&amp;quot;Effect&amp;quot;&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;:&lt;/span&gt; &lt;span class=&#39;s2&#39;&gt;&amp;quot;Allow&amp;quot;&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;,&lt;/span&gt;
      &lt;span class=&#39;nt&#39;&gt;&amp;quot;Action&amp;quot;&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;:&lt;/span&gt; &lt;span class=&#39;s2&#39;&gt;&amp;quot;s3:ListAllMyBuckets&amp;quot;&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;,&lt;/span&gt;
      &lt;span class=&#39;nt&#39;&gt;&amp;quot;Resource&amp;quot;&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;:&lt;/span&gt; &lt;span class=&#39;s2&#39;&gt;&amp;quot;*&amp;quot;&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;,&lt;/span&gt;
      &lt;span class=&#39;nt&#39;&gt;&amp;quot;Condition&amp;quot;&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;:&lt;/span&gt; &lt;span class=&#39;p&#39;&gt;{}&lt;/span&gt;
    &lt;span class=&#39;p&#39;&gt;}&lt;/span&gt;
  &lt;span class=&#39;p&#39;&gt;]&lt;/span&gt;
&lt;span class=&#39;p&#39;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Interstingly enough to access a bucket, you also need the right to list all the buckets.&lt;/p&gt;</description>
                <link>http://dev.baeck.at/amazon/2014/04/05/How-to-limit-Amazon-S3-access-to-one-bucket-only</link>
                <guid>http://dev.baeck.at/amazon/2014/04/05/How-to-limit-Amazon-S3-access-to-one-bucket-only</guid>
                <pubDate>2014-04-05T00:00:00-07:00</pubDate>
        </item>

        <item>
                <title>Embedding Youtube iframes into Jekyll</title>
                <description>&lt;p&gt;With Xcode 5.0.1 and Mavericks the Xcode command line tool is no longer available through Xcode. You need to install it manually. You need the command line tools to compile stuff or for example to run Mac Ports.&lt;/p&gt;

&lt;p&gt;There are many ways to install the command line tools. If you are running OS X 10.9 the command line is your friend:&lt;/p&gt;
&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;bash&#39;&gt;xcode-select --install
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;You can also do it via XCode itself. Just go to Preferences &amp;gt; Downloads.&lt;/p&gt;

&lt;p&gt;And finally download it manually at &lt;a href=&quot;https://developer.apple.com/downloads/index.action&quot;&gt;https://developer.apple.com/downloads/index.action&lt;/a&gt;.&lt;/p&gt;</description>
                <link>http://dev.baeck.at/sysadmin/2014/01/01/Embedding-Youtube-iframes-into-jekyll</link>
                <guid>http://dev.baeck.at/sysadmin/2014/01/01/Embedding-Youtube-iframes-into-jekyll</guid>
                <pubDate>2014-01-01T00:00:00-08:00</pubDate>
        </item>

        <item>
                <title>Hosting a Jekyll Blog on Github</title>
                <description>&lt;p&gt;For this blog and some others I use Jekyll and github to run. This has many advantages. Github cares about the hosting and scaling stuff and even the deployment is only a git push away.&lt;/p&gt;

&lt;p&gt;Jekyll is a static blogging engine written in ruby. I do not know shit about ruby, but it simply works very well.&lt;/p&gt;

&lt;p&gt;To run your own Jekyll blog on Github just follow the steps outlined &lt;a href=&quot;http://jekyllbootstrap.com/usage/jekyll-quick-start.html&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;To make it run on your custom domain, just create a file called CNAME in the root directory of your repository and just put your custom domain insdie it.&lt;/p&gt;

&lt;p&gt;Finally the above only describes hosting a blog on github pages for one account, but you can do this for as many accounts as your wish. Just create a new repository and push your jekyll data to the branach “gh-pages” like I do it &lt;a href=&quot;https://github.com/geraldbaeck/eve.baeck.at/tree/gh-pages&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;</description>
                <link>http://dev.baeck.at/sysadmin/2013/12/30/Hosting-a-Jekyll-Blog-on-github</link>
                <guid>http://dev.baeck.at/sysadmin/2013/12/30/Hosting-a-Jekyll-Blog-on-github</guid>
                <pubDate>2013-12-30T00:00:00-08:00</pubDate>
        </item>

        <item>
                <title>Install Sublime Text 3 Package Control</title>
                <description>&lt;ul&gt;
&lt;li&gt;Go to Preferences =&amp;gt; Browse Packages… menu&lt;/li&gt;

&lt;li&gt;Go up a folder into the Installed Packages/ directory&lt;/li&gt;

&lt;li&gt;Download &lt;a href=&quot;https://sublime.wbond.net/Package%20Control.sublime-package&quot;&gt;Control.sublime-package&lt;/a&gt; and copy it into the Installed Packages/ directory&lt;/li&gt;

&lt;li&gt;Restart Sublime Text&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Even easier:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Open console via ctrl+´ or the View &amp;gt; Show Console menu&lt;/li&gt;

&lt;li&gt;Paste this nasty litte piece of python code into the console&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;python&#39;&gt;&lt;span class=&#39;kn&#39;&gt;import&lt;/span&gt; &lt;span class=&#39;nn&#39;&gt;urllib.request&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;,&lt;/span&gt;&lt;span class=&#39;nn&#39;&gt;os&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;;&lt;/span&gt; &lt;span class=&#39;n&#39;&gt;pf&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&amp;#39;Package Control.sublime-package&amp;#39;&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;;&lt;/span&gt; &lt;span class=&#39;n&#39;&gt;ipp&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;n&#39;&gt;sublime&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;.&lt;/span&gt;&lt;span class=&#39;n&#39;&gt;installed_packages_path&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;();&lt;/span&gt; &lt;span class=&#39;n&#39;&gt;urllib&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;.&lt;/span&gt;&lt;span class=&#39;n&#39;&gt;request&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;.&lt;/span&gt;&lt;span class=&#39;n&#39;&gt;install_opener&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;(&lt;/span&gt; &lt;span class=&#39;n&#39;&gt;urllib&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;.&lt;/span&gt;&lt;span class=&#39;n&#39;&gt;request&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;.&lt;/span&gt;&lt;span class=&#39;n&#39;&gt;build_opener&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;(&lt;/span&gt; &lt;span class=&#39;n&#39;&gt;urllib&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;.&lt;/span&gt;&lt;span class=&#39;n&#39;&gt;request&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;.&lt;/span&gt;&lt;span class=&#39;n&#39;&gt;ProxyHandler&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;())&lt;/span&gt; &lt;span class=&#39;p&#39;&gt;);&lt;/span&gt; &lt;span class=&#39;nb&#39;&gt;open&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;n&#39;&gt;os&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;.&lt;/span&gt;&lt;span class=&#39;n&#39;&gt;path&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;.&lt;/span&gt;&lt;span class=&#39;n&#39;&gt;join&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;n&#39;&gt;ipp&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;,&lt;/span&gt; &lt;span class=&#39;n&#39;&gt;pf&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;),&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&amp;#39;wb&amp;#39;&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;.&lt;/span&gt;&lt;span class=&#39;n&#39;&gt;write&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;n&#39;&gt;urllib&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;.&lt;/span&gt;&lt;span class=&#39;n&#39;&gt;request&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;.&lt;/span&gt;&lt;span class=&#39;n&#39;&gt;urlopen&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;(&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&amp;#39;http://sublime.wbond.net/&amp;#39;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt; &lt;span class=&#39;n&#39;&gt;pf&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;.&lt;/span&gt;&lt;span class=&#39;n&#39;&gt;replace&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&amp;#39; &amp;#39;&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;,&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&amp;#39;%20&amp;#39;&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;))&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;.&lt;/span&gt;&lt;span class=&#39;n&#39;&gt;read&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;())&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;via &lt;a href=&quot;https://sublime.wbond.net/installation#st3&quot;&gt;sublime.wbond.net&lt;/a&gt;&lt;/p&gt;</description>
                <link>http://dev.baeck.at/sublime3/2013/11/19/Install-Sublime-Text-3-Package-Control</link>
                <guid>http://dev.baeck.at/sublime3/2013/11/19/Install-Sublime-Text-3-Package-Control</guid>
                <pubDate>2013-11-19T00:00:00-08:00</pubDate>
        </item>

        <item>
                <title>Python use MySQL column names instead of numbers</title>
                <description>&lt;p&gt;Instead of:&lt;/p&gt;
&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;python&#39;&gt;&lt;span class=&#39;n&#39;&gt;cursor&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;n&#39;&gt;conn&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;.&lt;/span&gt;&lt;span class=&#39;n&#39;&gt;cursor&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;()&lt;/span&gt;
&lt;span class=&#39;n&#39;&gt;cursor&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;.&lt;/span&gt;&lt;span class=&#39;n&#39;&gt;execute&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&amp;quot;SELECT name, value FROM table&amp;quot;&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;n&#39;&gt;result_set&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;n&#39;&gt;cursor&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;.&lt;/span&gt;&lt;span class=&#39;n&#39;&gt;fetchall&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;()&lt;/span&gt;
&lt;span class=&#39;k&#39;&gt;for&lt;/span&gt; &lt;span class=&#39;n&#39;&gt;row&lt;/span&gt; &lt;span class=&#39;ow&#39;&gt;in&lt;/span&gt; &lt;span class=&#39;n&#39;&gt;result_set&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;:&lt;/span&gt;
    &lt;span class=&#39;k&#39;&gt;print&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&#39;si&#39;&gt;%s&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;, &lt;/span&gt;&lt;span class=&#39;si&#39;&gt;%s&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&amp;quot;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&lt;/span&gt; &lt;span class=&#39;p&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;n&#39;&gt;row&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;mi&#39;&gt;0&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;],&lt;/span&gt; &lt;span class=&#39;n&#39;&gt;row&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;mi&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Just do this:&lt;/p&gt;
&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;python&#39;&gt;&lt;span class=&#39;n&#39;&gt;cursor&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;n&#39;&gt;conn&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;.&lt;/span&gt;&lt;span class=&#39;n&#39;&gt;cursor&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;n&#39;&gt;MySQLdb&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;.&lt;/span&gt;&lt;span class=&#39;n&#39;&gt;cursors&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;.&lt;/span&gt;&lt;span class=&#39;n&#39;&gt;DictCursor&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;n&#39;&gt;cursor&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;.&lt;/span&gt;&lt;span class=&#39;n&#39;&gt;execute&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&amp;quot;SELECT name, value FROM table&amp;quot;&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;n&#39;&gt;result_set&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;n&#39;&gt;cursor&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;.&lt;/span&gt;&lt;span class=&#39;n&#39;&gt;fetchall&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;()&lt;/span&gt;
&lt;span class=&#39;k&#39;&gt;for&lt;/span&gt; &lt;span class=&#39;n&#39;&gt;row&lt;/span&gt; &lt;span class=&#39;ow&#39;&gt;in&lt;/span&gt; &lt;span class=&#39;n&#39;&gt;result_set&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;:&lt;/span&gt;
    &lt;span class=&#39;k&#39;&gt;print&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&#39;si&#39;&gt;%s&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;, &lt;/span&gt;&lt;span class=&#39;si&#39;&gt;%s&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&amp;quot;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&lt;/span&gt; &lt;span class=&#39;p&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;n&#39;&gt;row&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&amp;quot;name&amp;quot;&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;],&lt;/span&gt; &lt;span class=&#39;n&#39;&gt;row&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&amp;quot;value&amp;quot;&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Nice to know and saved 3 lines of code!-)&lt;/p&gt;</description>
                <link>http://dev.baeck.at/python/2013/09/27/Python-mysql-use-column-names-instead-of-numbers</link>
                <guid>http://dev.baeck.at/python/2013/09/27/Python-mysql-use-column-names-instead-of-numbers</guid>
                <pubDate>2013-09-27T00:00:00-07:00</pubDate>
        </item>

        <item>
                <title>Python if else one liner</title>
                <description>&lt;p&gt;Instead of:&lt;/p&gt;
&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;python&#39;&gt;&lt;span class=&#39;k&#39;&gt;def&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;func&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;n&#39;&gt;x&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;):&lt;/span&gt;
    &lt;span class=&#39;k&#39;&gt;if&lt;/span&gt; &lt;span class=&#39;n&#39;&gt;x&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;mi&#39;&gt;0&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;:&lt;/span&gt;
        &lt;span class=&#39;k&#39;&gt;return&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&amp;quot;something&amp;quot;&lt;/span&gt;
    &lt;span class=&#39;k&#39;&gt;else&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;:&lt;/span&gt;
        &lt;span class=&#39;k&#39;&gt;return&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&amp;quot;something else&amp;quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Just do this:&lt;/p&gt;
&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;python&#39;&gt;&lt;span class=&#39;k&#39;&gt;def&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;func&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;n&#39;&gt;x&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;):&lt;/span&gt;
    &lt;span class=&#39;k&#39;&gt;return&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&amp;quot;something&amp;quot;&lt;/span&gt; &lt;span class=&#39;k&#39;&gt;if&lt;/span&gt; &lt;span class=&#39;n&#39;&gt;x&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;mi&#39;&gt;0&lt;/span&gt; &lt;span class=&#39;k&#39;&gt;else&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&amp;quot;something else&amp;quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Nice to know and saved 3 lines of code!-)&lt;/p&gt;</description>
                <link>http://dev.baeck.at/python/2013/08/08/Python-if-else-one-liner</link>
                <guid>http://dev.baeck.at/python/2013/08/08/Python-if-else-one-liner</guid>
                <pubDate>2013-08-08T00:00:00-07:00</pubDate>
        </item>

        <item>
                <title>Getting started with Sublime Text 3</title>
                <description>&lt;ol&gt;
&lt;li&gt;Download it &lt;a href=&quot;http://www.sublimetext.com/3&quot;&gt;here&lt;/a&gt;&lt;/li&gt;

&lt;li&gt;Install &lt;a href=&quot;http://wbond.net/sublime_packages/package_control/installation#ST3&quot;&gt;Package Control for Sublime Text 3&lt;/a&gt;&lt;/li&gt;

&lt;li&gt;Gi&lt;/li&gt;

&lt;li&gt;For python install: SublimeRope &lt;a href=&quot;https://github.com/SublimeLinter/SublimeLinter&quot;&gt;SublimeLinter&lt;/a&gt; AdvancedNewFile&lt;/li&gt;
&lt;/ol&gt;</description>
                <link>http://dev.baeck.at/devops/2013/07/30/Getting-started-with-sublime-text-3</link>
                <guid>http://dev.baeck.at/devops/2013/07/30/Getting-started-with-sublime-text-3</guid>
                <pubDate>2013-07-30T00:00:00-07:00</pubDate>
        </item>

        <item>
                <title>Secure your ssh server</title>
                <description>&lt;p&gt;While ssh is pretty secure, your should consider making it even more secure, by adding some of these steps.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;#disablekeys&quot;&gt;Use keys instead of passwords&lt;/a&gt;&lt;/li&gt;

&lt;li&gt;&lt;a href=&quot;#disableroot&quot;&gt;Disable login as root&lt;/a&gt;&lt;/li&gt;

&lt;li&gt;&lt;a href=&quot;#denyhosts&quot;&gt;Install denyhosts&lt;/a&gt;&lt;/li&gt;

&lt;li&gt;&lt;a href=&quot;#changesshport&quot;&gt;Change your ssh port&lt;/a&gt;&lt;/li&gt;

&lt;li&gt;&lt;a href=&quot;#iptables&quot;&gt;Configure a firewall (iptables)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Caution: Whenever making changes to your sshd.config file, be certain that you have an active shell session in case you’ve made a fatal syntax error. After restarting sshd, log in from another session to test it before terminating your active terminal session.&lt;/em&gt;&lt;/p&gt;

&lt;h3 id=&quot;disablekeys&quot;&gt;Passwords are bad - use keys&lt;/h3&gt;

&lt;p&gt;Passwords are always a kind of obscure security mechanism. A better and certainly more secure mechanism is to use ssh keys for all users. If ypu want to know how to generate a new user with his own key, have a look at &lt;a href=&quot;/devops/2013/07/24/Add-an-ssh-user-with-key-to-an-EC2-instance&quot;&gt;this guide&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;To disable Password-based Login log in to your instance and edit the ssh daemon configuration file:&lt;/p&gt;
&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;bash&#39;&gt;sudo nano /etc/ssh/sshd_config
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Find the line&lt;/p&gt;
&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;bash&#39;&gt;PasswordAuthentication yes
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;and change it to&lt;/p&gt;
&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;bash&#39;&gt;PasswordAuthentication no
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Don’t forget to restart sshd:&lt;/p&gt;
&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;bash&#39;&gt;sudo service ssh restart
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3 id=&quot;disableroot&quot;&gt;Disable Root Login&lt;/h3&gt;

&lt;p&gt;One of the biggest security holes you could open on your server is to allow directly logging in as root through ssh, because anyone can attempt to brute force your root password. It’s much better to have a separate account that you regularly use and simply sudo to root when necessary. You should make sure that you have a regular user account and that you can su or sudo to root from it.&lt;/p&gt;

&lt;p&gt;We need to edit the sshd_config file, which is the main configuration file for the sshd service.&lt;/p&gt;
&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;bash&#39;&gt;sudo nano /etc/ssh/sshd_config
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Find this section in the file, containing the line with “PermitRootLogin” in it. Set it to “no” to disable logging in through ssh as root.&lt;/p&gt;
&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;bash&#39;&gt;PermitRootLogin no
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;You could restrict the access via ssh to certain users. I highly recommend that.&lt;/p&gt;
&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;bash&#39;&gt;AllowUsers user1, user2, user3
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;And finally restart your ssh service&lt;/p&gt;
&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;bash&#39;&gt;sudo service ssh restart
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3 id=&quot;denyhosts&quot;&gt;Install denyhosts&lt;/h3&gt;

&lt;p&gt;DenyHosts is a security tool that monitors server access logs to prevent brute force attacks It works by banning IP addresses that exceed a certain number of failed login attempts.&lt;/p&gt;

&lt;p&gt;DenyHosts is very easy to install:&lt;/p&gt;
&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;bash&#39;&gt;sudo apt-get install denyhosts
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;After you install DenyHosts, make sure to whitelist your own IP address. Skipping this step will put you at risk of locking yourself out of your own machine.&lt;/p&gt;

&lt;p&gt;Open up the list of allowed hosts allowed on your server:&lt;/p&gt;
&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;bash&#39;&gt;sudo nano /etc/hosts.allow
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Under the description, add in any IP addresses that cannot afford to be banned from the server; you can write each one on a separate line, using this format:&lt;/p&gt;
&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;bash&#39;&gt;sshd: 12.34.45.678
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;After making any changes, be sure to restart DenyHosts so that the new settings take effect on your virtual private server:&lt;/p&gt;
&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;bash&#39;&gt;sudo service denyhosts restart
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;DenyHosts is ready use as soon as the installation is over, but if you want to customize DenyHosts, you can make the changes within the DenyHost configuration file:&lt;/p&gt;
&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;bash&#39;&gt;sudo nano /etc/denyhosts.conf
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3 id=&quot;changesshport&quot;&gt;Change your ssh port&lt;/h3&gt;

&lt;p&gt;There are many &lt;a href=&quot;http://serverfault.com/questions/189282/why-change-default-ssh-port&quot;&gt;discussions&lt;/a&gt; on the web about why changing your ssh from the default 22 to something else is a good or bad idea. Personally I think it is a good thing, because it adds a small security layer to the system. It is just like keeping your phone number out of the white pages. It won’t someone who really wants to call your doing that, but it will keep the kiddies away.&lt;/p&gt;

&lt;p&gt;Changing your port has some upsides:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Brute Force attack on port 22 are useless (Script Kiddies)&lt;/li&gt;

&lt;li&gt;It reduces the impact on your log files&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And also some downsides:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It can be a pain to explain other users that they can’t use the default port and how to change that&lt;/li&gt;

&lt;li&gt;Some restrictive outgoing firewalls are blocking non standard ports and only allow connections to for example 22, 25, 80, 443&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I think if a port change causes you even some trouble, it is probably not worth the effort because there are far more effictive ways to protect your server.&lt;/p&gt;

&lt;p&gt;If you do move away from 22, make sure it is below 1024. Under most Unix-a-like setups in their default config, only root users can listen on ports below 1024, but any user can listen on the higher ports. Running ssh on a higher port increases the chance of a rogue (or hacked) user managing to compromise your SSH daemon. You can find a list of known port numbers &lt;a href=&quot;https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers&quot;&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So how to do it? Just edit the line “Port 22” in your /etc/ssh/sshd_config file&lt;/p&gt;

&lt;h3 id=&quot;iptables&quot;&gt;Optional: Set up a Firewall (iptables)&lt;/h3&gt;

&lt;p&gt;You should be pretty save right now, but what about us paranoid people, who believe that the NSA is looking into everything? Oh wait, they are. Maybe it is a good idea to add another line of defense: An iptables firewall. I would not recommend this if your server is running on EC2, because amazon already has very easy to handle firewall their so called Security Groups builtin.&lt;/p&gt;

&lt;p&gt;Check your default firewall rules by entering the following command:&lt;/p&gt;
&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;bash&#39;&gt;sudo iptables -L
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Have a look at the output. If you haven’t implemented any rules yet, you should see an empty ruleset:&lt;/p&gt;
&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;bash&#39;&gt;Chain INPUT &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;policy ACCEPT&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
target     prot opt &lt;span class=&#39;nb&#39;&gt;source               &lt;/span&gt;destination

Chain FORWARD &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;policy ACCEPT&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
target     prot opt &lt;span class=&#39;nb&#39;&gt;source               &lt;/span&gt;destination

Chain OUTPUT &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;policy ACCEPT&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
target     prot opt &lt;span class=&#39;nb&#39;&gt;source               &lt;/span&gt;destination
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;First you need to create a configuration file for your firewall:&lt;/p&gt;
&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;bash&#39;&gt;sudo nano /etc/iptables.firewall.rules
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Copy and paste the rules shown below in to the iptables.firewall.rules file you just created.&lt;/p&gt;
&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;bash&#39;&gt;*filter

&lt;span class=&#39;c&#39;&gt;#  Allow all loopback (lo0) traffic and drop all traffic to 127/8 that doesn&amp;#39;t use lo0&lt;/span&gt;
-A INPUT -i lo -j ACCEPT
-A INPUT -d 127.0.0.0/8 -j REJECT

&lt;span class=&#39;c&#39;&gt;#  Accept all established inbound connections&lt;/span&gt;
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

&lt;span class=&#39;c&#39;&gt;#  Allow all outbound traffic - you can modify this to only allow certain traffic&lt;/span&gt;
-A OUTPUT -j ACCEPT

&lt;span class=&#39;c&#39;&gt;#  Allow HTTP and HTTPS connections from anywhere (the normal ports for websites and SSL).&lt;/span&gt;
-A INPUT -p tcp --dport 80 -j ACCEPT
-A INPUT -p tcp --dport 443 -j ACCEPT

&lt;span class=&#39;c&#39;&gt;#  Allow SSH connections&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#  The -dport number should be the same port number you set in sshd_config&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&lt;/span&gt;
-A INPUT -p tcp -m state --state NEW --dport 22 -j ACCEPT

&lt;span class=&#39;c&#39;&gt;#  Allow ping&lt;/span&gt;
-A INPUT -p icmp -j ACCEPT

&lt;span class=&#39;c&#39;&gt;#  Log iptables denied calls&lt;/span&gt;
-A INPUT -m limit --limit 5/min -j LOG --log-prefix &lt;span class=&#39;s2&#39;&gt;&amp;quot;iptables denied: &amp;quot;&lt;/span&gt; --log-level 7

&lt;span class=&#39;c&#39;&gt;#  Drop all other inbound - default deny unless explicitly allowed policy&lt;/span&gt;
-A INPUT -j DROP
-A FORWARD -j DROP

COMMIT
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;By default, the this will allow traffic to the following services and ports: HTTP (80), HTTPS (443), SSH (22), and ping. All other ports will be blocked.&lt;/p&gt;

&lt;p&gt;Now let’s activate the firewall rules:&lt;/p&gt;
&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;bash&#39;&gt;sudo iptables-restore &amp;lt; /etc/iptables.firewall.rules
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Check your firewall rules again:&lt;/p&gt;
&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;bash&#39;&gt;sudo iptables -L
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;It should return this:&lt;/p&gt;
&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;bash&#39;&gt;Chain INPUT &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;policy ACCEPT&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
target     prot opt &lt;span class=&#39;nb&#39;&gt;source               &lt;/span&gt;destination
ACCEPT     all  --  anywhere             anywhere
REJECT     all  --  anywhere             127.0.0.0/8          reject-with icmp-port-unreachable
ACCEPT     all  --  anywhere             anywhere             state RELATED,ESTABLISHED
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:http
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:https
ACCEPT     tcp  --  anywhere             anywhere             state NEW tcp dpt:ssh
ACCEPT     icmp --  anywhere             anywhere
LOG        all  --  anywhere             anywhere             limit: avg 5/min burst 5 LOG level debug prefix &lt;span class=&#39;s2&#39;&gt;&amp;quot;iptables denied: &amp;quot;&lt;/span&gt;
DROP       all  --  anywhere             anywhere

Chain FORWARD &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;policy ACCEPT&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
target     prot opt &lt;span class=&#39;nb&#39;&gt;source               &lt;/span&gt;destination
DROP       all  --  anywhere             anywhere

Chain OUTPUT &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;policy ACCEPT&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
target     prot opt &lt;span class=&#39;nb&#39;&gt;source               &lt;/span&gt;destination
ACCEPT     all  --  anywhere             anywhere
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Finally you have to make sure that this configuration is loaded on startup. Start by creating a new script with the following command:&lt;/p&gt;
&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;bash&#39;&gt;sudo nano /etc/network/if-pre-up.d/firewall
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Copy and paste this lines in to the file you just created:&lt;/p&gt;
&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;bash&#39;&gt;&lt;span class=&#39;c&#39;&gt;#!/bin/sh&lt;/span&gt;
/sbin/iptables-restore &amp;lt; /etc/iptables.firewall.rules
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Set the script’s permissions to executable:&lt;/p&gt;
&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;bash&#39;&gt;sudo chmod +x /etc/network/if-pre-up.d/firewall
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;And you are done! Remember, you’ll need to edit the firewall rules later if you install other software or services. It can be a pain to look into configuration files of new serivices just to recognize hours later, that you just have to open a port at iptables.&lt;/p&gt;

&lt;p&gt;Are we really done now? Even more paranoid people could have a look into &lt;a href=&quot;https://en.wikipedia.org/wiki/Security-Enhanced_Linux&quot;&gt;SELinux&lt;/a&gt;.&lt;/p&gt;</description>
                <link>http://dev.baeck.at/devops/2013/07/24/Secure-your-ssh-server</link>
                <guid>http://dev.baeck.at/devops/2013/07/24/Secure-your-ssh-server</guid>
                <pubDate>2013-07-24T00:00:00-07:00</pubDate>
        </item>

        <item>
                <title>Add an ssh user with key to an Amazon EC2 instance</title>
                <description>&lt;p&gt;First you need to create a pair of keys on your local machine (replace “user” with your chosen username):&lt;/p&gt;
&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;bash&#39;&gt;ssh-keygen -b 1024 -f user -t dsa
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This will create 2 files: user (private key), user.pub (public key). Now copy the public key file to a temporary place on your instance:&lt;/p&gt;
&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;bash&#39;&gt;scp -i root *.pub ec2-your-instance-name.compute.amazonaws.com:/tmp
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Log in to the instance as root. For each user you are creating, add the user to your instance with the&lt;/p&gt;
&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;bash&#39;&gt;sudo adduser user
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;For simplicity’s sake, use the same “user” name as you did for key generation. Now we need to place the key into their ssh authorized keys file (replacing “user” with the username you chose earlier)&lt;/p&gt;
&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;bash&#39;&gt;sudo mkdir ~user/.ssh
sudo cat /tmp/user.pub &amp;gt;&amp;gt; ~user/.ssh/authorized_keys
sudo chmod 700 ~user/.ssh
sudo chmod 600 ~user/.ssh/authorized_keys
sudo chown user:user ~user/.ssh
sudo chown user:user ~user/.ssh/authorized_keys
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Now log in:&lt;/p&gt;
&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;bash&#39;&gt;ssh -i ~/.ssh/user -l user ec2-your-instance-name.compute.amazonaws.com
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;To add your new user to the sudoers list:&lt;/p&gt;
&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;bash&#39;&gt;sudo adduser user sudo
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Don’t forget, that you probably want to delete an old user:&lt;/p&gt;
&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;bash&#39;&gt;sudo userdel -r olduser
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</description>
                <link>http://dev.baeck.at/devops/2013/07/24/Add-an-ssh-user-with-key-to-an-EC2-instance</link>
                <guid>http://dev.baeck.at/devops/2013/07/24/Add-an-ssh-user-with-key-to-an-EC2-instance</guid>
                <pubDate>2013-07-24T00:00:00-07:00</pubDate>
        </item>

        <item>
                <title>Synchronize your ssh configuration across multiple machines with Dropbox</title>
                <description>&lt;p&gt;Working with many different Macs and servers daily can ba a pain. But you can store your SSH configuration file in dropbox, and create a symbolic link to it so you can use the same configuration across your computers.&lt;/p&gt;

&lt;p&gt;Also, you can use this method to sync other types of configuration files like your bash profile or your hosts file.&lt;/p&gt;

&lt;p&gt;Create a folder in your Dropbox to store such files.&lt;/p&gt;
&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;bash&#39;&gt;mkdir ~/Dropbox/symlinks
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Move your ssh config to this folder.&lt;/p&gt;
&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;bash&#39;&gt;sudo mv /etc/ssh_config ~/Dropbox/symlinks/ssh_config
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Create a symbolic link to the new file.&lt;/p&gt;
&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;bash&#39;&gt;sudo ln -s ~/Dropbox/symlinks/ssh_config /etc/ssh_config
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</description>
                <link>http://dev.baeck.at/devops/2013/07/23/Synchronize-your-ssh-configuration-across-multiple-machines-with-Dropbox</link>
                <guid>http://dev.baeck.at/devops/2013/07/23/Synchronize-your-ssh-configuration-across-multiple-machines-with-Dropbox</guid>
                <pubDate>2013-07-23T00:00:00-07:00</pubDate>
        </item>

        <item>
                <title>Configure your favorite ssh hosts to type less</title>
                <description>&lt;p&gt;ssh is pretty straight forward. I spend years typing long lines into the console or setting up complicated UI to manage my favorite ssh hosts. But there are some tricks, which could save you a lot of time.&lt;/p&gt;

&lt;p&gt;At first, you need to create an ssh config file. If you are on a mac the file is located at /etc/ssh_config. All other unix-like machines should create the file in ~/.ssh/config. To check where the OS is looking for a config file you could also type&lt;/p&gt;
&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;bash&#39;&gt;ssh -v &lt;span class=&#39;nb&#39;&gt;test&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;It should return something like this:&lt;/p&gt;
&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;bash&#39;&gt;OpenSSH_5.9p1, OpenSSL 0.9.8x 10 May 2012
debug1: Reading configuration data /etc/ssh_config
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Make sure the file has read-write permission to only your user.&lt;/p&gt;
&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;bash&#39;&gt;chmod 600 /etc/ssh_config
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Now, configure a your favorite hosts in the ssh_config file&lt;/p&gt;
&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;bash&#39;&gt;Host example
HostName example.com
Port 667
User username
IdentityFile ~/.ssh/id_rsa
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Now, instead of writing this:&lt;/p&gt;
&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;bash&#39;&gt;ssh -i ~/.ssh/id_rsa -p 4431 username@example.com 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;You can write this:&lt;/p&gt;
&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;bash&#39;&gt;ssh example
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;As a small benefit this also works with scp.&lt;/p&gt;
&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;bash&#39;&gt;scp /path/to/some/file example
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Now let’s tunnel. If you are used to write this, to make a connection to a remote mySQL database&lt;/p&gt;
&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;bash&#39;&gt;ssh -f -N -i ~/.ssh/id_rsa -L 9906:127.0.0.1:3306 username@database.example.com
&lt;span class=&#39;c&#39;&gt;# -f puts ssh in background &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;# -N makes it not execute a remote command &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;You should consider modifying your config like this:&lt;/p&gt;
&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;bash&#39;&gt;Host tunnel
HostName database.example.com
IdentityFile ~/.ssh/id_rsa
LocalForward 9906 127.0.0.1:3306
User username
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;To be able to finally establish a tunnel with this command:&lt;/p&gt;
&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;bash&#39;&gt;ssh -f -N tunnel
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</description>
                <link>http://dev.baeck.at/devops/2013/07/23/Preconfigure-your-favorite-ssh-hosts-to-type-less</link>
                <guid>http://dev.baeck.at/devops/2013/07/23/Preconfigure-your-favorite-ssh-hosts-to-type-less</guid>
                <pubDate>2013-07-23T00:00:00-07:00</pubDate>
        </item>

        <item>
                <title>Add EC2 pem key permanently to ssh</title>
                <description>&lt;p&gt;Add your pem key to SSH so you do not have to manually specify it when connecting to EC2 instances.&lt;/p&gt;

&lt;p&gt;With this command:&lt;/p&gt;
&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;bash&#39;&gt;    ssh-add ~/.ssh/KEY_PAIR_NAME.pem
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;You can do this:&lt;/p&gt;
&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;bash&#39;&gt;    ssh ec2-instance.amazonaws.com
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;instead of:&lt;/p&gt;
&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;bash&#39;&gt;    ssh -i ~/.ssh/KEY_PAIR_NAME.pem ec2-instance.amazonaws.com
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</description>
                <link>http://dev.baeck.at/devops/2013/07/23/Add-EC2-pem-key-permanently-to-ssh</link>
                <guid>http://dev.baeck.at/devops/2013/07/23/Add-EC2-pem-key-permanently-to-ssh</guid>
                <pubDate>2013-07-23T00:00:00-07:00</pubDate>
        </item>

        <item>
                <title>Configuring Wifi on your Raspberry Pi</title>
                <description>&lt;p&gt;There are many ways how to configure wifi on the Raspberry Pi. Most of them are complicated and messy. I found this solution the easiest to apply. One important thing is, that this will not work with a hidden wifi. You will always have to broadcast your network’s ssid.&lt;/p&gt;

&lt;p&gt;Connect to you Pi via ssh and type&lt;/p&gt;
&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;bash&#39;&gt;sudo nano /etc/network/interfaces
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;You should see something like this&lt;/p&gt;
&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;bash&#39;&gt;auto lo

iface lo inet loopback
iface eth0 inet dhcp

allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Edit it this way&lt;/p&gt;
&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;bash&#39;&gt;auto lo

iface lo inet loopback
iface eth0 inet dhcp

auto wlan0
allow-hotplug wlan0
iface wlan0 inet dhcp
wpa-ssid &lt;span class=&#39;s2&#39;&gt;&amp;quot;YOUR_NETWORK_SSID_HERE&amp;quot;&lt;/span&gt;
wpa-psk &lt;span class=&#39;s2&#39;&gt;&amp;quot;YOUR_WIFI_PASSOWRD_HERE&amp;quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Finally unplug your network cable, reboot your Pi and check ifconfig if you have an active wifi connection.&lt;/p&gt;
&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;bash&#39;&gt;sudo reboot
ifconfig
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;ifconfig should return something like this. The important thing is to see an assigned IP address in the wlan0 section.&lt;/p&gt;
&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;bash&#39;&gt;eth0      Link encap:Ethernet  HWaddr b8:27:eb:95:4d:5d
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;0.0 B&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;  TX bytes:0 &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;0.0 B&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;0.0 B&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;  TX bytes:0 &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;0.0 B&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

wlan0     Link encap:Ethernet  HWaddr 80:1f:02:97:4e:c2
          inet addr:10.0.1.6  Bcast:10.0.1.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:3692 errors:0 dropped:3978 overruns:0 frame:0
          TX packets:402 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:356570 &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;348.2 KiB&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;  TX bytes:55122 &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;53.8 KiB&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Troubleshooting&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Is your network not hidden?&lt;/li&gt;

&lt;li&gt;It does not work without a password&lt;/li&gt;

&lt;li&gt;Are the password and the ssid with double brackets?&lt;/li&gt;
&lt;/ul&gt;</description>
                <link>http://dev.baeck.at/rapsberrypi/2013/07/11/configuring-wifi-on-your-raspberry-pi</link>
                <guid>http://dev.baeck.at/rapsberrypi/2013/07/11/configuring-wifi-on-your-raspberry-pi</guid>
                <pubDate>2013-07-11T01:33:58-07:00</pubDate>
        </item>

        <item>
                <title>AES encryption with pycrypto</title>
                <description>&lt;p&gt;Why encrypting anything, when there are already hashes? Hashes work really well especially when they are properly salted for passwords, but if you use OAuth connections from Facebook, Twitter etc., passwords are becoming less important. Access Tokens are now the new way to access a users information, but we cannot simply hash them, because to access users Facebook information, we still need the token. So the only way o store it more secure is to encrypt it.&lt;/p&gt;

&lt;p&gt;Encryption and decryption via pycrypto can be pretty tough. It is not as convenient as the &lt;a href=&#39;https://dev.mysql.com/doc/refman/5.1/en/encryption-functions.html&#39;&gt;AES_ENCRYPT&lt;/a&gt; function in mysql and the documentation is worse than none. But anyway it’s Open Source and it is good to have it. It takes more effort to understand the library and if you want to have true interoperability between different plattforms and languages you need to understand it anyway.&lt;/p&gt;

&lt;p&gt;How is that encryption working? Basically you have a key and a message. The key is some kind of password you need it to encrypt and decrypt the message. But the key has to be 16, 24 or 36 letters long not more not less and also the message has to be a multiple of 16, 24 or 32. Don’t ask why, I don’t know that too and I don’t care!-) So what we need to do is to pad our key with a filling char to get to the exact length. If you haven’t chosen a key yet I would recommend to chose an exactly 32 character long key, os you don’t have to pad it. As padding character I chose the ‘{‘ because the padding will be at the end of the text and it is most unlikely that the text will end with a ‘{‘. The same thing goes for the text. The text also needs to be a multiple of 16, so we have to pad that too.&lt;/p&gt;

&lt;p&gt;But I chose a different way for the key. I simply hash it with MD5 and get automatically a 32 character key back. Obviously you can’t do that with the text/value to encrypt.&lt;/p&gt;
&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;python&#39;&gt;&lt;span class=&#39;c&#39;&gt;#!/usr/bin/env python&lt;/span&gt;

&lt;span class=&#39;kn&#39;&gt;from&lt;/span&gt; &lt;span class=&#39;nn&#39;&gt;Crypto.Cipher&lt;/span&gt; &lt;span class=&#39;kn&#39;&gt;import&lt;/span&gt; &lt;span class=&#39;n&#39;&gt;AES&lt;/span&gt;
&lt;span class=&#39;kn&#39;&gt;from&lt;/span&gt; &lt;span class=&#39;nn&#39;&gt;Crypto.Hash&lt;/span&gt; &lt;span class=&#39;kn&#39;&gt;import&lt;/span&gt; &lt;span class=&#39;n&#39;&gt;MD5&lt;/span&gt;
&lt;span class=&#39;kn&#39;&gt;from&lt;/span&gt; &lt;span class=&#39;nn&#39;&gt;base64&lt;/span&gt; &lt;span class=&#39;kn&#39;&gt;import&lt;/span&gt; &lt;span class=&#39;n&#39;&gt;encodestring&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;,&lt;/span&gt; &lt;span class=&#39;n&#39;&gt;decodestring&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;#base64 encoding to enable json dumps&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# the block size for the key and message must be 16, 24, or 32 for AES&lt;/span&gt;
&lt;span class=&#39;n&#39;&gt;BLOCK_SIZE&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;mi&#39;&gt;32&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# the character used for padding--with a block cipher such as AES, the value&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;# you encrypt must be a multiple of BLOCK_SIZE in length.  This character is&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;# used to ensure that your value is always a multiple of BLOCK_SIZE&lt;/span&gt;
&lt;span class=&#39;n&#39;&gt;PADDING&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&amp;#39;{&amp;#39;&lt;/span&gt;

&lt;span class=&#39;k&#39;&gt;def&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;pad&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;n&#39;&gt;msg&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;,&lt;/span&gt; &lt;span class=&#39;n&#39;&gt;block_size&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;=&lt;/span&gt;&lt;span class=&#39;n&#39;&gt;BLOCK_SIZE&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;,&lt;/span&gt; &lt;span class=&#39;n&#39;&gt;padding&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;=&lt;/span&gt;&lt;span class=&#39;n&#39;&gt;PADDING&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;):&lt;/span&gt;
    &lt;span class=&#39;sd&#39;&gt;&amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
&lt;span class=&#39;sd&#39;&gt;    *pad the text to be encrypted*&lt;/span&gt;
&lt;span class=&#39;sd&#39;&gt;    - appends a padding character to the end of the String&lt;/span&gt;
&lt;span class=&#39;sd&#39;&gt;    - until the string has block_size length&lt;/span&gt;

&lt;span class=&#39;sd&#39;&gt;    &amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
    &lt;span class=&#39;k&#39;&gt;return&lt;/span&gt; &lt;span class=&#39;n&#39;&gt;msg&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt; &lt;span class=&#39;p&#39;&gt;((&lt;/span&gt;&lt;span class=&#39;n&#39;&gt;block_size&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt; &lt;span class=&#39;nb&#39;&gt;len&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;n&#39;&gt;msg&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&lt;/span&gt; &lt;span class=&#39;n&#39;&gt;block_size&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;*&lt;/span&gt; &lt;span class=&#39;n&#39;&gt;padding&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;k&#39;&gt;def&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;depad&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;n&#39;&gt;msg&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;,&lt;/span&gt; &lt;span class=&#39;n&#39;&gt;padding&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;=&lt;/span&gt;&lt;span class=&#39;n&#39;&gt;PADDING&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;):&lt;/span&gt;
    &lt;span class=&#39;sd&#39;&gt;&amp;quot;&amp;quot;&amp;quot;depad the decryptet message&amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
    &lt;span class=&#39;k&#39;&gt;return&lt;/span&gt; &lt;span class=&#39;n&#39;&gt;msg&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;.&lt;/span&gt;&lt;span class=&#39;n&#39;&gt;rstrip&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;n&#39;&gt;padding&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;k&#39;&gt;def&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;getSecret&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;n&#39;&gt;key&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;):&lt;/span&gt;
    &lt;span class=&#39;sd&#39;&gt;&amp;quot;&amp;quot;&amp;quot;hases the key to MD5&amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
    &lt;span class=&#39;k&#39;&gt;return&lt;/span&gt; &lt;span class=&#39;n&#39;&gt;MD5&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;.&lt;/span&gt;&lt;span class=&#39;n&#39;&gt;new&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;n&#39;&gt;key&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;.&lt;/span&gt;&lt;span class=&#39;n&#39;&gt;hexdigest&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;()&lt;/span&gt;

&lt;span class=&#39;k&#39;&gt;def&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;encrypt&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;n&#39;&gt;key&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;,&lt;/span&gt; &lt;span class=&#39;n&#39;&gt;msg&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;):&lt;/span&gt;
    &lt;span class=&#39;sd&#39;&gt;&amp;quot;&amp;quot;&amp;quot;encrypts the message&amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
    &lt;span class=&#39;n&#39;&gt;secret&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;n&#39;&gt;getSecret&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;n&#39;&gt;key&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;)&lt;/span&gt;
    &lt;span class=&#39;n&#39;&gt;cipher&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;n&#39;&gt;AES&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;.&lt;/span&gt;&lt;span class=&#39;n&#39;&gt;new&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;n&#39;&gt;secret&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;)&lt;/span&gt;
    &lt;span class=&#39;k&#39;&gt;return&lt;/span&gt; &lt;span class=&#39;n&#39;&gt;encodestring&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;n&#39;&gt;cipher&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;.&lt;/span&gt;&lt;span class=&#39;n&#39;&gt;encrypt&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;n&#39;&gt;pad&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;n&#39;&gt;msg&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;)))&lt;/span&gt;

&lt;span class=&#39;k&#39;&gt;def&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;decrypt&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;n&#39;&gt;key&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;,&lt;/span&gt; &lt;span class=&#39;n&#39;&gt;msg&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;):&lt;/span&gt;
    &lt;span class=&#39;sd&#39;&gt;&amp;quot;&amp;quot;&amp;quot;decrypts the message&amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
    &lt;span class=&#39;n&#39;&gt;secret&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;n&#39;&gt;doSecret&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;n&#39;&gt;key&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;)&lt;/span&gt;
    &lt;span class=&#39;n&#39;&gt;cipher&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;n&#39;&gt;AES&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;.&lt;/span&gt;&lt;span class=&#39;n&#39;&gt;new&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;n&#39;&gt;secret&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;)&lt;/span&gt;
    &lt;span class=&#39;k&#39;&gt;return&lt;/span&gt; &lt;span class=&#39;n&#39;&gt;depad&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;((&lt;/span&gt;&lt;span class=&#39;n&#39;&gt;cipher&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;.&lt;/span&gt;&lt;span class=&#39;n&#39;&gt;decrypt&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;n&#39;&gt;decodestring&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;n&#39;&gt;msg&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;))))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;You should not use this as a library, because there is no error handling implemented. For example what happens if the key is longer than the block_size, etc.. This script is just demo the encryption process with pycrypto.&lt;/p&gt;</description>
                <link>http://dev.baeck.at/python/2012/04/12/AES-encryption-with-pycrypto</link>
                <guid>http://dev.baeck.at/python/2012/04/12/AES-encryption-with-pycrypto</guid>
                <pubDate>2012-04-12T00:00:00-07:00</pubDate>
        </item>


</channel>
</rss>
