<?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>64k &#187; administration</title>
	<atom:link href="http://www.64k-tec.de/tag/administration/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.64k-tec.de</link>
	<description>Software development and more ...</description>
	<lastBuildDate>Tue, 10 Jan 2012 21:58:41 +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>TT: Uni-directional file synchronization between different hosts with Unison</title>
		<link>http://www.64k-tec.de/2011/11/tt-uni-directional-file-synchronization-between-different-hosts-with-unison/</link>
		<comments>http://www.64k-tec.de/2011/11/tt-uni-directional-file-synchronization-between-different-hosts-with-unison/#comments</comments>
		<pubDate>Thu, 10 Nov 2011 21:19:25 +0000</pubDate>
		<dc:creator>cp</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[Root]]></category>
		<category><![CDATA[administration]]></category>
		<category><![CDATA[Bash]]></category>
		<category><![CDATA[Console]]></category>
		<category><![CDATA[directory management]]></category>
		<category><![CDATA[file synchronization]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[OpenSSH]]></category>
		<category><![CDATA[remote access]]></category>
		<category><![CDATA[Rsync]]></category>
		<category><![CDATA[secure communication]]></category>
		<category><![CDATA[ssh]]></category>
		<category><![CDATA[synchronization]]></category>
		<category><![CDATA[Synchronizer]]></category>
		<category><![CDATA[tooltips]]></category>
		<category><![CDATA[TT]]></category>
		<category><![CDATA[Unison]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[X11]]></category>

		<guid isPermaLink="false">http://www.64k-tec.de/?p=2561</guid>
		<description><![CDATA[When you work with at least two computers on the same project on a daily basis you might have a problem. You need to get changed files from host A to host B and vice versa. The problem getting bigger when you work in addition on different operation systems or use more than two hosts. [...]]]></description>
			<content:encoded><![CDATA[<p>When you work with at least two computers on the same project on a daily basis you might have a problem. You need to get changed files from host A to host B and vice versa. The problem getting bigger when you work in addition on different operation systems or use more than two hosts. On UNIX/Linux the preferred tool for such a task is <a title="Rsync - fast incremental file transfer" href="http://rsync.samba.org/" target="_blank">Rsync</a>. Unfortunately Rsync synchronize only in one direction, it doesn't work very well when more than two hosts are involved (and it isn't really comfortable to set up on Windows) and can't use a secure communication channel. Another approach is to check-in changed source files into a <a title="Wikipedia: Revision Control Systems" href="http://en.wikipedia.org/wiki/Revision_control" target="_blank">version control system</a>, like <a title="Wikipedia: Concurrent Versions System" href="http://en.wikipedia.org/wiki/Concurrent_Versions_System" target="_blank">CVS</a>. On host A you check it in and on host B you check it out afterwards. But this means you always need a more or less stable variant of your code, so that other developer can, at least compile, or much better use it. That is not always the case (especially when you leave the office at 11:00 p.m.) and it also doesn't cover files which aren't handled by a version control system. Luckily there is a solution for all the problems mentioned which is called <a title="Unison - A File Synchronizer" href="http://www.cis.upenn.edu/~bcpierce/unison/" target="_blank">Unison</a>. So here comes the second post in the <a title="ToolTips - Useful applications for the daily business" href="/tag/tt/">ToolTips</a> series, which covers an easy and portable way for file synchronization.</p>
<h2>Installing Unison</h2>
<p>Most modern Linux distributions include Unison in their package manage system. On Mac OS X you can use <a title="The MacPorts Project Official Homepage" href="http://www.macports.org/" target="_blank">MacPorts</a>. Alternatively you could download a binary version for Mac OS X or Windows <a title="Binary versions of Unison" href="http://alan.petitepomme.net/unison/index.html" target="_blank">here</a>. To prevent surprises and unnecessary trouble it might be a good idea to make sure that every involved system use the same version of Unison. At least on Linux and Mac OS X it is relatively easy to compile Unison from the <a title="Unison sources" href="http://www.cis.upenn.edu/~bcpierce/unison/download.html" target="_blank">sources</a>.</p>
<h2>Setting up public/private key authentication for ssh</h2>
<p>One advantage of Unison over Rsync is that you can use different communication channels for the file transfers. One is ssh. As I always prefer/demand encrypted communication this is a big plus of course. In the default setup you can just use ssh. But for a little bit more comfort I suggest to create a public/private key pair for the authentication.<br />
<span class="sb_alert">The following creates public/private keys without a password. Although this is much more easier to use, it should be only used on hosts which are trusted. If you are in doubt, use the normal password approach or even better create a public/private key pair with a password.</span> Create a new public/private key pair with the following command:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">user<span style="color: #000000; font-weight: bold;">@</span>host-a ~ $ <span style="color: #c20cb9; font-weight: bold;">ssh-keygen</span> <span style="color: #660033;">-t</span> rsa</pre></div></div>

<p>When you are asked for a password just hit Enter twice. The command creates the private key in <code class="path">~/.ssh/id_rsa</code> and the public key in <code class="path">~/.ssh/id_rsa.pub</code>. Now copy the public key to host B:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">user<span style="color: #000000; font-weight: bold;">@</span>host-a ~ $ <span style="color: #c20cb9; font-weight: bold;">scp</span> ~<span style="color: #000000; font-weight: bold;">/</span>.ssh<span style="color: #000000; font-weight: bold;">/</span>id_rsa.pub host_B:.ssh<span style="color: #000000; font-weight: bold;">/</span>authorized_keys</pre></div></div>

<p>If you already have some public keys on host B, make sure you append the new key and not overwrite the file by the above command. Make the file accessible by the user only with:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">user<span style="color: #000000; font-weight: bold;">@</span>host-b ~ $ <span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">600</span> ~<span style="color: #000000; font-weight: bold;">/</span>.ssh<span style="color: #000000; font-weight: bold;">/</span>authorized_keys</pre></div></div>

<p>Now you should be able to connect to host B without any interaction needed.</p>
<h2>Configuring Unison</h2>
<p>Like in the long UNIX tradition, Unison is configured using text files. The files are located in the <code class="path">~/.unison</code> directory. You can configure more than one synchronization target by choosing a meaningful name. There exists one default target which is configured in the file <code class="path">default.prf</code>. Because I have more than one target I prefer to split the configuration into several files. You can include other project files with the <code>include</code> statement as shown here:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># directory on host a (this is where Unison will be executed)</span>
root       = <span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span>data<span style="color: #000000; font-weight: bold;">/</span>projects
<span style="color: #666666; font-style: italic;"># directory on host b (this is the remote host)</span>
root       = <span style="color: #c20cb9; font-weight: bold;">ssh</span>:<span style="color: #000000; font-weight: bold;">//</span>host-b<span style="color: #000000; font-weight: bold;">//</span>mnt<span style="color: #000000; font-weight: bold;">/</span>data<span style="color: #000000; font-weight: bold;">/</span>projects
<span style="color: #666666; font-style: italic;"># which directories to sync?</span>
include projects_files.prf
<span style="color: #666666; font-style: italic;"># options</span>
include options.prf
ignorecase = <span style="color: #c20cb9; font-weight: bold;">false</span>
<span style="color: #666666; font-style: italic;"># unison executable on the server</span>
servercmd  = <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>unison</pre></div></div>

<p>We setup the root directories on both machines, including the configuration file for the project target and some generic option file. We also overwriting the default unison location, because this is a self compiled version. The file <code class="path">options.prf</code> looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># No staled nfs and mac store files</span>
ignore  = Name .nfs<span style="color: #000000; font-weight: bold;">*</span>
ignore  = Name .DS_Store
<span style="color: #666666; font-style: italic;"># options</span>
log     = <span style="color: #c20cb9; font-weight: bold;">true</span>
rsrc    = <span style="color: #c20cb9; font-weight: bold;">true</span>
auto    = <span style="color: #c20cb9; font-weight: bold;">true</span>
<span style="color: #666666; font-style: italic;">#debug   = verbose</span>
<span style="color: #666666; font-style: italic;">#logfile = ~/.unison/unison.log</span></pre></div></div>

<p>This just set some generic options which are valid for all my targets. For the specific target <strong>projects</strong> the file <code class="path">projects_files.prf</code> contains mainly the directories and files which should be ignored:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># No ISOs</span>
ignore    = Path vms<span style="color: #000000; font-weight: bold;">/</span>ISO
<span style="color: #666666; font-style: italic;"># Ignore VBox branches</span>
ignore    = Path vbox-<span style="color: #000000; font-weight: bold;">*</span>
<span style="color: #666666; font-style: italic;"># No binary output from the other platforms</span>
ignore    = Path vbox<span style="color: #000000; font-weight: bold;">*/</span>out<span style="color: #000000; font-weight: bold;">/*</span>
<span style="color: #666666; font-style: italic;"># One exception:</span>
ignorenot = Path vbox<span style="color: #000000; font-weight: bold;">/</span>out<span style="color: #000000; font-weight: bold;">/</span>linux.amd64.additions
<span style="color: #666666; font-style: italic;"># No wine stuff</span>
ignore    = Path vbox<span style="color: #000000; font-weight: bold;">*/</span>wine.<span style="color: #000000; font-weight: bold;">*</span>
<span style="color: #666666; font-style: italic;"># Tools</span>
ignore    = Name vbox<span style="color: #000000; font-weight: bold;">*/</span>tools<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>FetchDir,freebsd<span style="color: #000000; font-weight: bold;">*</span>,os2<span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<p>So in general, you configure the directory to synchronize and later define directories or files which should be ignored. As you see, you can include or exclude paths as you like. Even simple bash wildcards are possible. As shown in this example I exclude all binary files of a VirtualBox build, because they are useless on another platform. Understanding how Unison decide which directories or files should be synchronized is sometimes difficult. So I suggest to carefully read the <a title="Unison - Documentation" href="http://www.cis.upenn.edu/~bcpierce/unison/download/releases/stable/unison-manual.html" target="_blank">documentation</a> and just use the "try and failure" approach <img src='http://www.64k-tec.de/wordpress/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> . Another reason for splitting up the configuration files is you can synchronize these files as well. I have another target which synchronize several configuration files, e.g. <code class="path">.bashrc</code>, <code class="path">.profile</code>, <code class="path">.vim*</code> and the sub-project files of Unison like the <code class="path">projects_files.prf</code>. You can't synchronize e.g. <code class="path">default.prf</code>, cause the root directories are different from host to host, but the general configuration is always the same. My <strong>home</strong> target looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># Which directories/files to sync?</span>
path = .bashrc
path = .ion3
path = .gdbinit
path = .cgdb
path = .valgrind-vbox.supp
path = .vim
path = .vimrc
path = .gvimrc
path = .Xdefaults
path = .gnupg
path = .unison<span style="color: #000000; font-weight: bold;">/</span>options.prf
path = .unison<span style="color: #000000; font-weight: bold;">/</span>home_files.prf
path = .unison<span style="color: #000000; font-weight: bold;">/</span>projects_files.prf
<span style="color: #666666; font-style: italic;"># Do not sync:</span>
ignore = Path .vim<span style="color: #000000; font-weight: bold;">/</span>.netrwhist
ignore = Path .ion3<span style="color: #000000; font-weight: bold;">/</span>default-session<span style="color: #000000; font-weight: bold;">*</span>
ignore = Path .cgdb<span style="color: #000000; font-weight: bold;">/</span>readline_history.txt</pre></div></div>

<p>One of the strengths over other synchronization tools is, you can do this for others host as well. So if you synchronize between host a and host b you can also synchronize between host c and host b. However, a little bit of discipline is necessary. There should be one host which all other host synchronize again.<br />
If you now execute <code class="cmd">unison</code> the project target will be used. If you execute <code class="cmd">unison home</code> the files of the home target will be synchronized.</p>
<h2>Conclusion</h2>
<p>Unison is a very powerful tool. You can synchronize between more than two hosts (OS independent), in a secure way and uni-directional. Currently there is no better tool and I use it on a daily basis.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.64k-tec.de/2011/11/tt-uni-directional-file-synchronization-between-different-hosts-with-unison/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FRITZ!Box tuning part 4: Cross-building and installing additional applications</title>
		<link>http://www.64k-tec.de/2011/07/fritzbox-tuning-part-4-cross-building-and-installing-additional-applications/</link>
		<comments>http://www.64k-tec.de/2011/07/fritzbox-tuning-part-4-cross-building-and-installing-additional-applications/#comments</comments>
		<pubDate>Tue, 26 Jul 2011 20:14:36 +0000</pubDate>
		<dc:creator>cp</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[Root]]></category>
		<category><![CDATA[administration]]></category>
		<category><![CDATA[boot]]></category>
		<category><![CDATA[Buildroot]]></category>
		<category><![CDATA[Console]]></category>
		<category><![CDATA[cross-building]]></category>
		<category><![CDATA[cross-compiling]]></category>
		<category><![CDATA[dropbear]]></category>
		<category><![CDATA[firmware]]></category>
		<category><![CDATA[FritzBox]]></category>
		<category><![CDATA[gcc]]></category>
		<category><![CDATA[glibc]]></category>
		<category><![CDATA[installation]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[MIPS]]></category>
		<category><![CDATA[OpenSSH]]></category>
		<category><![CDATA[overlay]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[ssh]]></category>
		<category><![CDATA[tmpfs]]></category>
		<category><![CDATA[Toolchain]]></category>

		<guid isPermaLink="false">http://www.64k-tec.de/?p=2338</guid>
		<description><![CDATA[The articles I wrote about the FRITZ!Box are pretty popular. They are creating the most traffic on my website. I understand this, cause the FRITZ!Box is a really great piece of hardware and AVM is also a company which knows how to make their users happy by serving regular updates to the firmware. Although I [...]]]></description>
			<content:encoded><![CDATA[<p>The articles I wrote about the <a href="/tag/fritzbox/" target="_blank">FRITZ!Box</a> are pretty popular. They are creating the most traffic on my website. I understand this, cause the FRITZ!Box is a really great piece of hardware and AVM is also a company which knows how to make their users happy by serving regular updates to the firmware. Although I didn't tuned my FRITZ!Box any further, I updated it with the latest <a href="http://www.avm.de/de/Service/Service-Portale/Labor/index.php" target="_blank">Labor</a> firmware version regularly. At some point the sshd setup (with dropbear) doesn't worked anymore and I decided it is the time to update my software as well. Beside that it didn't work anymore it is always a good idea to update software which allow access to a host from everywhere very regularly. Anyway, it turned out this isn't as simple as I initial thought. Therefore here is the next post in the FRITZ!Box tuning series, which shows how to cross-build software for the MIPS32 architecture used in the FRITZ!Box and in particular get the sshd software to life again. I use a FRITZ!Box Fon WLAN 7270 v2 and the firmware is 54.05.05. Please make sure you read the other <a href="/tag/fritzbox/" target="_blank">FRITZ!Box articles</a> as well, cause some of the information given there still applies.</p>
<span class="sb_alert">As already mentioned in the other articles, there is no warranty that this will work on your side and I am not responsible for any damage which may happen. You have been warned!</span>
<h2>Cross-building for the MIPS32 architecture</h2>
<p>The FRITZ!Box itself doesn't include any build tools. Why should it! It's an end-consumer product which is usually never changed, beside the user is updating it with an official firmware update. So we have to do it ourself. Creating a build chain for another architecture is usually <a href="http://www.landley.net/writing/docs/cross-compiling.html" target="_blank">hard</a>. There are several things you have to consider. This includes problems with the configuration, endianess differences between the host and the target, bit depths and depending shared libraries which have to be available in the target format. Fortunately this is a common problem, especially for embedded systems, which means there is a proper solution called <a href="http://buildroot.uclibc.org/" target="_blank">Buildroot</a> (look at the first line in <code class="cmd">dmsg</code>, when the FRITZ!Box has booted and you know what I mean). Buildroot is a build system which allows, similar to the Linux kernel, configuring and generating complete embedded Linux systems. Regardless how configured, Buildroot builds a complete Linux system, always. This is of course a little bit overhead for us, but we just pick out the relevant files. First we need to know which architecture we target. You have to login into the FRITZ!Box either using <a href="http://www.64k-tec.de/2010/01/fritzbox-tuning-part-1-enable-remote-access-over-ssh/" target="_blank">telnet or a working ssh daemon</a>. To get some information about the hardware used in your FRITZ!Box execute <code class="cmd">cat /proc/cpuinfo</code>.</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;"># cat /proc/cpuinfo
system type             : TI UR8 (7270)
processor               : 0
cpu model               : MIPS 4KEc V6.8
BogoMIPS                : 359.62
wait instruction        : yes
microsecond timers      : yes
tlb_entries             : 16
extra interrupt vector  : yes
hardware watchpoint     : no
ASEs implemented        :
shadow register sets    : 1
core                    : 0
VCED exceptions         : not available
VCEI exceptions         : not available</pre></div></div>

<p>Here we learn that the FRITZ!Box is using a <a href="http://www.mips.com/products/cores/hard-ip-cores/4kec-hard-ip-cores/" target="_blank">MIPS</a> processor. In this case it uses the <a href="http://en.wikipedia.org/wiki/Endianness" target="_blank">little-endian</a> format. Next you need some information about the system C library. On normal Linux (desktop) systems the GNU C Library is used. This library is heavyweight and therefore the <a href="http://uclibc.org/" target="_blank">uClibc</a> was invented for embedded systems. By executing <code class="cmd">ls /lib/libuClibc*</code> you get the version installed. In my case it is 0.9.31. Now we have all information needed to configure Buildroot. <a href="http://buildroot.uclibc.org/download.html" target="_blank">Download</a> and extract the source of Buildroot.</p>
<span class="sb_tip">If you are working on a Mac like me (where Buildroot doesn't work), <a href="http://www.virtualbox.org/" target="_blank">VirtualBox</a> with a Linux system as a guest is a good alternative <img src='http://www.64k-tec.de/wordpress/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> .</span>
<p>By executing <code class="cmd">make menuconfig</code> in the root directory of Buildroot you are able to configure it. The most important options are <strong>Target Architecture</strong>, set this to <code>mipsel</code> and <strong>Target Architecture Variant</strong>, set this to <code>mips 32r2</code>. In <strong>Toolchain -&gt; uClibc C library Version</strong> select a version which is close to the one on your FRITZ!Box. Next you have to select which packages should be build in <strong>Package Selection for the target</strong>. Choose whatever you want but for the beginning <strong>Networking applications -&gt; openssh</strong> might be enough. If you prefer a more lightweight ssh implementation <strong>dropbear</strong> may also an option. In the following we use OpenSSH. You can also tweak the build options, like the <code class="cmd">gcc</code> version to use or set the gcc optimization level to <code>-O3</code> in favor of size. After saving the configuration and executing <code class="cmd">make</code>, it is time for a coffee. When the build has been finished all relevant files are in <code class="path">output/target/</code>. We only pack the directories and files which are necessary. For example the <code>libuClibc</code> was built by Buildroot, but we will use the one from the FRITZ!Box. The following create a zip archive of the files for OpenSSH.<a name="zip"></a></p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">zip -r ../../local.zip &quot;lib/libutil* lib/libnsl* lib/libresolv* \
 lib/libcrypt* usr/lib usr/share usr/sbin usr/bin etc/ssh_config \
 etc/sshd_config&quot;</pre></div></div>

<h2>Creating overlay directories on the root filesystem</h2>
<p>The following is based on ideas invented by the guys at <a href="http://www.spblinux.de/fbox.new/" target="_blank">http://www.spblinux.de/</a>. Our aim is it to have as little persistent changes on the FRITZ!Box as possible. This allows us to go back to the original state with a simple reboot. Therefore all writeable directories will be on a <a href="http://en.wikipedia.org/wiki/Tmpfs" target="_blank">tmpfs</a> filesystem. tmpfs filesystems are created in RAM and the content will be removed when the filesystem is unmounted. Because the FRITZ!Box has only limited RAM, we will not copy our applications into the tmpfs filesystem, but just create symbolic links to the files on the USB stick (where usually much more space is available). Because we want the applications from the FRITZ!Box and our own one be accessible from the root filesystem, we need to merge both into the tmpfs directory. Therefore first symbolic links into the original filesystem and second symbolic links to the USB stick are created. The second step is only performed when there isn't a file already. This makes sure the original files are always preferred over our own one. The last step is binding the directories to the root filesystem. Summarized the following will be done:</p>
<ol>
<li>remount <code class="path">/</code> readonly</li>
<li>mount <code class="path">/</code> into <code class="path">/var/_ro_</code></li>
<li>create tmpfs in <code class="path">/var/_overlay_</code></li>
<li>symlink the files from <code class="path">/var/_ro_</code> into <code class="path">/var/_overlay_</code></li>
<li>symlink the files from the USB stick into <code class="path">/var/_overlay_</code></li>
<li>bind the directories in <code class="path">/var/_overlay_</code> to <code class="path">/</code></li>
</ol>
<p>This script does the previous steps. It uses helper methods which are defined in <code class="path">common.sh</code>. You will find all the necessary files in the package you can download at the end of this article.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
&nbsp;
. common.sh
&nbsp;
<span style="color: #007800;">MNT</span>=<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>_overlay_
<span style="color: #007800;">BASE_RO</span>=<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>_ro_
<span style="color: #007800;">BASE_OVL</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">${BASE}</span>/local&quot;</span>
&nbsp;
<span style="color: #007800;">DIRS</span>=<span style="color: #ff0000;">&quot;lib etc usr/bin usr/sbin usr/lib usr/share&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># remount root readonly</span>
<span style="color: #ff0000;">&quot;<span style="color: #007800;">${MOUNT}</span>&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${GREP}</span>&quot;</span> <span style="color: #ff0000;">&quot;/dev/root&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${GREP}</span>&quot;</span> <span style="color: #660033;">-q</span> ro
<span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$?</span> <span style="color: #660033;">-eq</span> <span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> _lmt <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>root <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #ff0000;">&quot;-o remount -r&quot;</span>
<span style="color: #666666; font-style: italic;"># bind root into var</span>
_lchkmnt <span style="color: #ff0000;">&quot;<span style="color: #007800;">${BASE_RO}</span>&quot;</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$?</span> <span style="color: #660033;">-eq</span> <span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
  _lmkdir <span style="color: #ff0000;">&quot;<span style="color: #007800;">${BASE_RO}</span>&quot;</span>
  _lmnt <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${BASE_RO}</span>&quot;</span> <span style="color: #ff0000;">&quot;-o bind&quot;</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># create our overlay dir</span>
_lchkmnt <span style="color: #ff0000;">&quot;<span style="color: #007800;">${MNT}</span>&quot;</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$?</span> <span style="color: #660033;">-eq</span> <span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
  _lmkdir <span style="color: #ff0000;">&quot;<span style="color: #007800;">${MNT}</span>&quot;</span>
  _lmnt tmpfs <span style="color: #ff0000;">&quot;<span style="color: #007800;">${MNT}</span>&quot;</span> <span style="color: #ff0000;">&quot;-t tmpfs&quot;</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># link/copy the base stuff</span>
<span style="color: #000000; font-weight: bold;">for</span> i <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #800000;">${DIRS}</span>; <span style="color: #000000; font-weight: bold;">do</span>
  _lsymlnk_dir <span style="color: #ff0000;">&quot;<span style="color: #007800;">${BASE_RO}</span>&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${i}</span>&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${MNT}</span>&quot;</span>
<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># link/copy our own stuff</span>
<span style="color: #000000; font-weight: bold;">for</span> i <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #800000;">${DIRS}</span>; <span style="color: #000000; font-weight: bold;">do</span>
  _lsymlnk_dir <span style="color: #ff0000;">&quot;<span style="color: #007800;">${BASE_OVL}</span>&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${i}</span>&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${MNT}</span>&quot;</span>
<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># now bind all overlay dirs to root</span>
<span style="color: #666666; font-style: italic;"># (this is critical don't interupt)</span>
<span style="color: #000000; font-weight: bold;">for</span> i <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #800000;">${DIRS}</span>; <span style="color: #000000; font-weight: bold;">do</span>
  _lmnt <span style="color: #ff0000;">&quot;<span style="color: #007800;">${MNT}</span>/<span style="color: #007800;">${i}</span>&quot;</span> <span style="color: #ff0000;">&quot;/<span style="color: #007800;">${i}</span>&quot;</span> <span style="color: #ff0000;">&quot;-o bind&quot;</span>
<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">0</span></pre></div></div>

<p>Now copy the zip archive you have created <a href="#zip">above</a> to the FRITZ!Box and unpack it on the USB stick in <code class="path">addons/local/</code>. The scripts have to be placed into <code class="path">addons/</code>. You need to configure the following in <code class="path">common.sh</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;"># the base of the usb stick goes here:
BASE=&quot;/var/media/ftp/FLASH-DISK-01/addons&quot;
# add the encrypted root password here:
PASS=&quot;&quot;</pre></div></div>

<p>Point to the base directory within the USB stick in <code>BASE</code>. Also add your encrypted root password into <code>PASS</code>. This will create a root user in <code class="path">/etc/passwd</code> automatically.</p>
<p>If you believe all is correct, you can start the installation by executing <code class="cmd">./install.sh</code>. If no errors are shown, you can try ssh. <code class="cmd">ssh -v</code> should output something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;"># ssh -v
OpenSSH_5.8p2, OpenSSL 1.0.0d 8 Feb 2011
...</pre></div></div>

<p>Additional to the standard filesystems mounted, you should see the following when executing <code class="cmd">mount</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;"># mount
...
/dev/root on /var/_ro_ type squashfs (ro,relatime)
tmpfs on /var/_overlay_ type tmpfs (rw,relatime)
tmpfs on /lib type tmpfs (rw,relatime)
tmpfs on /etc type tmpfs (rw,relatime)
tmpfs on /usr/bin type tmpfs (rw,relatime)
tmpfs on /usr/sbin type tmpfs (rw,relatime)
tmpfs on /usr/lib type tmpfs (rw,relatime)
tmpfs on /usr/share type tmpfs (rw,relatime)</pre></div></div>

<h2>Configure and start the OpenSSH daemon</h2>
<p>Now that we have our brand new OpenSSH on the FRITZ!Box working, we need some last steps to let the daemon running correctly. First create a private/public RSA host key pair for the server process by executing:</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">ssh-keygen -t rsa -f addons/config/ssh_host_rsa_key</pre></div></div>

<p><code class="path">addons/config/</code> have to be an existing directory below the USB stick base. Next create a file <code class="path">addons/config/sshd_config</code> in the same directory with the following content:</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">Protocol               2
UsePrivilegeSeparation no
Subsystem              sftp /usr/lib/sftp-server</pre></div></div>

<p>The following script could be use to start the <code class="cmd">sshd</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
&nbsp;
. common.sh
&nbsp;
<span style="color: #007800;">SSHD</span>=<span style="color: #ff0000;">&quot;/usr/sbin/sshd&quot;</span>
<span style="color: #007800;">SSH_SPKEY</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">${BASE}</span>/config/ssh_host_rsa_key&quot;</span>
<span style="color: #007800;">SSH_CFG</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">${BASE}</span>/config/sshd_config&quot;</span>
<span style="color: #007800;">SSH_TPKEY</span>=<span style="color: #ff0000;">&quot;/var/tmp/ssh_host_rsa_key&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># sanity check</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${SSHD}</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> _lce <span style="color: #007800;">$?</span> <span style="color: #ff0000;">&quot;sshd not installed&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># start in tmp</span>
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>tmp   
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">mount</span> <span style="color: #660033;">-o</span> remount devpts <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>pts <span style="color: #660033;">-t</span> devpts
&nbsp;
<span style="color: #666666; font-style: italic;"># cp key and make them user readable only</span>
_lcp_file <span style="color: #ff0000;">&quot;<span style="color: #007800;">${SSH_SPKEY}</span>&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${SSH_TPKEY}</span>&quot;</span>
_lchmod <span style="color: #000000;">400</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${SSH_TPKEY}</span>&quot;</span>             
&nbsp;
<span style="color: #666666; font-style: italic;"># start sshd</span>
<span style="color: #ff0000;">&quot;<span style="color: #007800;">${SSHD}</span>&quot;</span> <span style="color: #660033;">-f</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${SSH_CFG}</span>&quot;</span> <span style="color: #660033;">-h</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${SSH_TPKEY}</span>&quot;</span></pre></div></div>

<p>Please note that you have to set up the root user first and maybe adjust your port forwarding rules to allow access from the Internet as described in this <a href="http://www.64k-tec.de/2010/01/fritzbox-tuning-part-1-enable-remote-access-over-ssh/" target="_blank">post</a>. The package will contain a script <code class="cmd">startup.sh</code> which will add the root user automatically.</p>
<p>Here is the obligatory screenshot which shows <code class="cmd">htop</code> with color terminal support. You see OpenSSH and OpenVPN in the list of the running processes.</p>
<p style="text-align: center;"><a href="/wordpress/wp-content/uploads/htop-e1311594537898.png"><img class="aligncenter size-medium wp-image-2427" title="htop" src="/wordpress/wp-content/uploads/htop-e1311594537898-300x176.png" alt="" width="300" height="176" /></a></p>
<h2>Conclusion</h2>
<p>Thanks to Buildroot it is pretty easy to cross-build for embedded machines these days. With some tricky directory rebinding new applications could be injected into the FRITZ!Box root filesystem without overwriting the existing firmware. Now you should be able to build any software already bundled with Buildroot or even <a href="http://buildroot.uclibc.org/buildroot.html#add_packages" target="_blank">add new one to the build process</a>. Happy cross-building!</p>
<span class="sb_download">You can download the scripts and binaries discussed in this post:<br />
<a href="/downloads/FRITZBox/FRITZBox_OpenSSH_5.8p2.tar.gz">FRITZBox_OpenSSH_5.8p2.tar.gz</a> (3.8MB, <a href="/downloads/FRITZBox/FRITZBox_OpenSSH_5.8p2.tar.gz-sha1.txt">SHA1</a>)</span>
]]></content:encoded>
			<wfw:commentRss>http://www.64k-tec.de/2011/07/fritzbox-tuning-part-4-cross-building-and-installing-additional-applications/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>TT: Console navigation the easy way with Apparix</title>
		<link>http://www.64k-tec.de/2011/05/tt-console-navigation-the-easy-way-with-apparix/</link>
		<comments>http://www.64k-tec.de/2011/05/tt-console-navigation-the-easy-way-with-apparix/#comments</comments>
		<pubDate>Sat, 14 May 2011 19:43:04 +0000</pubDate>
		<dc:creator>cp</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[Root]]></category>
		<category><![CDATA[administration]]></category>
		<category><![CDATA[Apparix]]></category>
		<category><![CDATA[Bash]]></category>
		<category><![CDATA[bookmark]]></category>
		<category><![CDATA[Console]]></category>
		<category><![CDATA[directory management]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[TT]]></category>
		<category><![CDATA[vim]]></category>
		<category><![CDATA[work environment]]></category>

		<guid isPermaLink="false">http://www.64k-tec.de/?p=2237</guid>
		<description><![CDATA[Today I will start a new series where I present small tools which I use on a daily basis and considered very useful. These tools haven't to be killer applications, but doing the task they are written for, very well. Therefor also the name of this series: TT, which stands for ToolTips. Most of this [...]]]></description>
			<content:encoded><![CDATA[<p>Today I will start a new series where I present small tools which I use on a daily basis and considered very useful. These tools haven't to be killer applications, but doing the task they are written for, very well. Therefor also the name of this series: <a href="/tag/TT/">TT</a>, which stands for ToolTips. Most of this applications are open source, so I will take the opportunity to say "Thank you" to all the people out there, which create such cool stuff in there free time.</p>
<p>We start with a tool called <a href="http://www.micans.org/apparix/" target="_blank">Apparix</a>.</p>
<h2>Console?</h2>
<p>As you may know, I'm a keyboard addict. My preferred OS is Linux, I use <a href="http://tuomov.iki.fi/software/" target="_blank">Ion3</a> as the window manager, <a href="http://software.schmorp.de/pkg/rxvt-unicode.html" target="_blank">rxvt-unicode</a> as terminal application and <a href="http://www.vim.org/" target="_blank">(g)Vim</a> as the preferred editor. On the other side I have a MacBook Pro as laptop and love the possibilities of Mac OS X. How does this come together? Well, all these tools are available on Mac OS X as well. The X11 port of Mac OS X is getting better with each release and using it in fullscreen is good enough. Mac OS X is based on BSD and together with <a href="http://www.macports.org/" target="_blank">MacPorts</a>, there is nothing I missed until today. As I have to work really platform independent, there is Windows. Vim is available, but working console based (read: <code>command.com</code>) isn't really much fun. There is of course <a href="http://www.mingw.org/" target="_blank">mingw</a>, but I never managed it to create a work environment like on Linux/UNIX. Anyway, I work not that much on Windows, so I can live with other tools there as well (a really good free editor is <a href="http://notepad-plus-plus.org/" target="_blank">Notepad++</a> and if you hate Explorer have a look at <a href="http://www.altap.cz/salam_en/index.html" target="_blank">Altap Salamander</a>). So the question remains: Console? I have the feeling using the keyboard within a console application is much faster than clicking around with the mouse. This doesn't mean I like to type every single character when starting an application or changing the current working directory. Many modern command interpreters, like the <a href="http://tiswww.case.edu/php/chet/bash/bashtop.html" target="_blank">Bash</a>, have built in word expansion. This allows you to use the tabulator key for fast expansion of typed characters for a given set of commands. Of course this makes the console life much more easier. But there is more!</p>
<h2>Bookmarking important directories</h2>
<p>Usually, I'm working on projects. One project is VirtualBox. Other might be some private stuff, like personal letters or other development I do. As the regular user organize his projects in directory trees it make sense to bookmark them. Most people believe bookmarking is something Internet specific, but this isn't true. Bookmarking means getting access to an important information very fast, without remembering the exact location of this information. This is exactly what Apparix does. It bookmarks directories and make these bookmarks easy accessible on the console. So I have bookmarks for sub-projects within VirtualBox, like the <a href="http://www.virtualbox.org/browser/trunk/src/VBox/Frontends/VirtualBox" target="_blank">GUI</a> or <a href="http://www.virtualbox.org/browser/trunk/src/VBox/Main" target="_blank">Main</a>. Getting there is as easy as writing <code class="cmd">to vgui</code>. It's the same as writing <code class="cmd">cd /bin</code> and it even provide word expansion of the available bookmarks. In this case the bookmark is <code>vgui</code> and it expand to the GUI directory within the VirtualBox source tree.</p>
<h2>How does this work?</h2>
<p>Installing Apparix is pretty simple. You will find all the information on the <a href="http://www.micans.org/apparix/" target="_blank">website</a>. The important part is the integration within your shell. You need to extent your <code class="path">.bashrc</code>. One way is to add the functions you need into <code class="path">.bashrc</code>. Alternatively you can download the file <a href="http://www.micans.org/apparix/bash_apparix" target="_blank"><code class="path">.bash_apparix</code></a> and source it in your <code class="path">.bashrc</code>. When you have done this and start a new shell, you should navigate to a directory you like to bookmark. There you type <code class="cmd">bm</code> to create your first bookmark. Afterwards, regardless what your current working directory is, you could execute <code class="cmd">to DIR_NAME</code> to get there. Of course you can name the bookmark other than the current directory name, by using <code class="cmd">bm MY_NAME</code>. By executing <code class="cmd">als</code> all bookmarks are shown. There is much more possible of course. See the documentation for more information. Anyway, this is the main use case for Apparix, so there is not much more to say. Really?</p>
<h2>Using the Apparix database for other applications</h2>
<p>The cool thing on many Linux applications is, they are saving their data in simple text files. Also Apparix. The bookmark "database" is saved in a file called <code class="path">.apparixrc</code>. It's a simple text file, which is easy to parse. It looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">j,vbox,/Users/poetzsch/projects/vbox
j,VirtualBox,/Users/poetzsch/projects/vbox/src/VBox/Frontends/VirtualBox
j,Main,/Users/poetzsch/projects/vbox/src/VBox/Main
j,Runtime,/Users/poetzsch/projects/vbox/src/VBox/Runtime
j,Installer,/Users/poetzsch/projects/vbox/src/VBox/Installer/darwin
j,cv,/Users/poetzsch/projects/private/office/latex/cv
j,dow,/Users/poetzsch/Downloads</pre></div></div>

<p>This allows the usage of this information in other contexts as well. One example is Vim. As I mentioned earlier, this is my main editor. So it would be cool to use the bookmarks, I already have, there as well. To easy change the current directory in Vim, add the following to your <code class="path">.vimrc</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="vim" style="font-family:monospace;"><span style="color: #668080;">command</span><span style="color: #000000;">!</span> <span style="color: #000000;">-</span><span style="color: #25BB4D;">complete</span>=custom,BmCe <span style="color: #668080;">-nargs</span>=<span style="color: #000000; font-weight:bold;">1</span> To <span style="color: #000000;">:</span><span style="color: #804040;">call</span> BmTo<span style="color: #000000;">&#40;</span><span style="color: #C5A22D;">'&lt;args&gt;'</span><span style="color: #000000;">&#41;</span>
<span style="color: #804040;">fun</span> BmCe<span style="color: #000000;">&#40;</span>A,L,P<span style="color: #000000;">&#41;</span>
 <span style="color: #804040;">return</span> <span style="color: #25BB4D;">system</span><span style="color: #000000;">&#40;</span><span style="color: #C5A22D;">&quot;awk 'BEGIN{FS=<span style="">\&quot;</span>,<span style="">\&quot;</span>}/j,/{print $2}' ~/.apparixrc&quot;</span><span style="color: #000000;">&#41;</span>
<span style="color: #668080;">endfun</span>
<span style="color: #804040;">fun</span> BmLs<span style="color: #000000;">&#40;</span><span style="color: #668080;">dir</span><span style="color: #000000;">&#41;</span>
 <span style="color: #804040;">return</span> <span style="color: #25BB4D;">system</span><span style="color: #000000;">&#40;</span><span style="color: #C5A22D;">'apparix '</span><span style="color: #000000;">.</span>a<span style="color: #000000;">:</span><span style="color: #668080;">dir</span><span style="color: #000000;">.</span><span style="color: #C5A22D;">' | tr -d &quot;<span style="">\n</span>&quot;'</span><span style="color: #000000;">&#41;</span>
<span style="color: #668080;">endfun</span>
<span style="color: #804040;">fun</span> BmTo<span style="color: #000000;">&#40;</span><span style="color: #668080;">dir</span><span style="color: #000000;">&#41;</span>
 <span style="color: #804040;">execute</span> <span style="color: #C5A22D;">':cd '</span><span style="color: #000000;">.</span>BmLs<span style="color: #000000;">&#40;</span>a<span style="color: #000000;">:</span><span style="color: #668080;">dir</span><span style="color: #000000;">&#41;</span>
<span style="color: #668080;">endfun</span></pre></div></div>

<p>After restarting Vim, it is possible to navigate with <code class="cmd">:To MY_BOOKMARK</code> to any directory known by Apparix.</p>
<h2>Conclusion</h2>
<p>One simple task, getting to a directory where you are often have to be, with one simple solution. Thats all to say about Apparix. It does this in a very simple way, which is fully integrated into the Bash and the saved information could be used by other applications as well.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.64k-tec.de/2011/05/tt-console-navigation-the-easy-way-with-apparix/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Installing Linux on a USB hard disk for the MacBook Pro</title>
		<link>http://www.64k-tec.de/2010/04/installing-linux-on-a-usb-hard-disk-for-the-macbook-pro/</link>
		<comments>http://www.64k-tec.de/2010/04/installing-linux-on-a-usb-hard-disk-for-the-macbook-pro/#comments</comments>
		<pubDate>Fri, 09 Apr 2010 02:29:11 +0000</pubDate>
		<dc:creator>cp</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[Root]]></category>
		<category><![CDATA[administration]]></category>
		<category><![CDATA[boot]]></category>
		<category><![CDATA[Boot Camp]]></category>
		<category><![CDATA[EFI]]></category>
		<category><![CDATA[FireWire]]></category>
		<category><![CDATA[Gentoo]]></category>
		<category><![CDATA[hard disk]]></category>
		<category><![CDATA[installation]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[MacBook Pro]]></category>
		<category><![CDATA[removable media]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[USB]]></category>

		<guid isPermaLink="false">http://www.64k-tec.de/?p=885</guid>
		<description><![CDATA[One of the features of Mac OS X I love, is the possibility to install Mac OS X on any attached removable media, like a FireWire or USB hard disk. This makes it really easy for me to test VirtualBox on the several versions of Mac OS X we support (formerly Tiger, now Leopard and [...]]]></description>
			<content:encoded><![CDATA[<p>One of the features of Mac OS X I love, is the possibility to install Mac OS X on any attached removable media, like a FireWire or USB hard disk. This makes it really easy for me to test VirtualBox on the several versions of Mac OS X we support (formerly Tiger, now Leopard and Snow Leopard). The advantage of this setup is that I don't waste disk space for operation systems I usually don't use very often. Currently I have a 150GB hard disk in my MacBook Pro which is really not that much if you deal in the virtualization business. There are several test VM's of any kind of guest operation systems and of course the ISO's to install them. The second main OS, I do much of my work, is Linux. For this I have a standard PC with Gentoo on it, which have all that I need. Unfortunately this doesn't really help when I on travel. As I soon be away for some time, I decided I need, at least for testing, the same flexibility mentioned above for a Linux installation. And here the problems start to arise. Of course Apple didn't really support installing other OS's than Mac OS X on Apple hardware. Yes, there is Boot Camp, but this is mainly for Windows, is very inflexible and doesn't really help if you try to install something on another place than the integrated hard disk. There are projects like <a href="http://refit.sourceforge.net/" target="_blank">rEFIt</a>, which even makes Boot Camp superfluous, but this project has really bad USB boot support. In the following I will explain how it is even possible to install Ubuntu 9.10 on a USB hard disk.</p>
<p>The hardware used, as already said, is a MacBook Pro 3,1 and a Western Digital My Passport Essential 500GB USB hard disk. Other combination may work, but I don't guarantee this, as always. Also you should be warned that anything I describe here could destroy your existing installation and I'm not responsible for that. Doing some kind of backup might be a good idea. Time Machine is easy to use <img src='http://www.64k-tec.de/wordpress/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> .</p>
<p>Before we start, as usual, the credits for some sites I get my information from. This is mainly the <a href="http://www.produnis.de/blog/?p=678" target="_blank">Produnis blog</a>, <a href="http://blog.christophersmart.com/2009/07/23/linux-on-an-apple-xserve-efi-only-machine/" target="_blank">the Blog of Chris</a>, the <a href="https://wiki.ubuntu.com/MactelSupportTeam/CommunityHelpPages" target="_blank">Ubuntu wiki</a> and of course the guys around the <a href="http://grub.enbug.org/TestingOnMacbook" target="_blank">Grub2</a> development.</p>
<h2>Creating the EFI boot loader</h2>
<p>Apple doesn't use the legacy BIOS to boot their machines, they use the <a href="http://en.wikipedia.org/wiki/Extensible_Firmware_Interface" target="_blank"><em>Extensible Firmware Interface</em></a> (EFI). This new way of booting operation systems is very flexible, as the name suggest, but has several drawbacks, like most of the standard operation system doesn't speaks it language. Although Linux can be configured to use EFI directly we will emulate a legacy BIOS in the following. For this we need a connector which makes EFI and Linux happy and let them both work smoothly together. This connector is <a href="http://www.gnu.org/software/grub/" target="_blank">Grub2</a>, which is in development for several years now. It's the successor of Grub and is the standard in many popular Linux distributions these days. We have to build a version our self, for which an existing Linux installation is really helpful. I used my 64-bit Gentoo installation. First you have to find out if the EFI installation on your target Apple machine is 64 or 32-bit. You can do this by executing:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">ioreg <span style="color: #660033;">-l</span> <span style="color: #660033;">-p</span> IODeviceTree <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> firmware-abi</pre></div></div>

<p>This will return EFI64 or EFI32 respectively. In my case I need the 64-bit version, which is a little bit surprising when I consider that my MacBook Pro isn't able to boot a 64-bit Snow Leopard. Anyway, grab the <a href="ftp://alpha.gnu.org/gnu/grub/grub-1.98.tar.gz">latest version</a> of Grub2 and unpack it on the Linux machine. Please note that you need a gcc with multilib support if you are targeting an architecture which isn't the same as the host one. Use the following to configure Grub2 and to build it. Of course you have to adjust the target architecture if it is a different one.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">.<span style="color: #000000; font-weight: bold;">/</span>configure <span style="color: #660033;">--with-platform</span>=efi <span style="color: #660033;">--target</span>=x86_64 <span style="color: #660033;">--disable-werror</span>
<span style="color: #c20cb9; font-weight: bold;">make</span></pre></div></div>

<p>When this is finished you create the EFI package by executing<a name="mkimage"></a></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">.<span style="color: #000000; font-weight: bold;">/</span>grub-mkimage <span style="color: #660033;">-d</span> . <span style="color: #660033;">-o</span> bootx86.efi <span style="color: #000000; font-weight: bold;">*</span>.mod</pre></div></div>

<p>Here I included all modules which are available. If size matter for you, you could of course make a selective choice on the modules included. I didn't test this myself, so you have to find out yourself which one are important.</p>
<h2>Whipping the USB hard disk into shape</h2>
<p style="text-align: left;">Next we have to prepare the USB hard disk for the new installation. In the following I assume your USB hard disk doesn't contain any valid data and could be reformatted without data lose. Make a backup of your data first if this isn't the case on your side. Apple uses the <a href="http://en.wikipedia.org/wiki/GUID_Partition_Table" target="_blank">GUID Partition Table</a> scheme to organize their partitions on a hard disk. This specification is part of EFI and remove many limitations of the <em><a href="http://en.wikipedia.org/wiki/Master_Boot_Record" target="_blank">Master boot record</a></em> (MBR) scheme, which is widely used in the PC world. That is e.g. the disk size limitation of 2TB or the maximum of 4 primary partitions. You reformat your disk, using the Disk Utility application of Mac OS X. Make sure all existing partitions on the disk are unmounted. When necessary, change the partition scheme from MBR to GUID in the Options dialog of the Partitions window. Select the partitions count you want to use. You need at least 3 partitions to make Linux works fine. My partition scheme looks like in the following: <a href="/wordpress/wp-content/uploads/Disk-Utility.png"><img class="aligncenter size-full wp-image-972" title="GUID Partition Table scheme" src="/wordpress/wp-content/uploads/Disk-Utility.png" alt="" width="188" height="390" /></a>As you can see I have 5 partitions configured. The first one is an additional Snow Leopard installation for testing. I also added a Data partition at the end for making the data transfer between the different operation systems as easy as possibly. LINUXBOOT is a small partition which will contain the EFI boot loader (size it 50MB or something like that). Linux Swap, obviously, will become the swap partition of the Linux installation. DISK1S5 is the Linux root partition itself. The Data partition has to be formated as Mac OS Extended. Don't use the Journaled version of HFS+, cause this makes trouble on the Linux side. The other partitions have to be formatted as MS-DOS (FAT).</p>
<p>After applying the changes we can add the EFI boot loader to the LINUXBOOT partition. The Apple EFI implementation is searching for a file with the efi extensions on all bootable hard disks. Mount LINUXBOOT and create a <code class="path">efi/boot</code> directory on the root path. Copy the <a href="#mkimage">bootx86.efi</a> file into the boot/ directory. As bootx86.efi is a Grub2 boot loader we need a valid Grub2 configuration file. The following <code class="path">grub.cfg</code> shows the configuration for a Ubuntu 9.10 i386 installation. For the 64-bit version or any other version of Ubuntu the settings might be slightly different.</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;"><span style="color: #000099;">menuviewer</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #933;">&quot;text&quot;</span>
<span style="color: #000099;">timeout</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">10</span>
<span style="color: #000099;">default</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">0</span>
set F1<span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">ctrl-x</span>
menuentry <span style="color: #933;">&quot;ubuntu-9.10-desktop-i386&quot;</span>
<span style="">&#123;</span>
 fakebios
 search --set -f /boot/vmlinuz-2.6.31-<span style="">14</span>-generic
 linux /boot/vmlinuz-2.6.31-<span style="">14</span>-generic root<span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">UUID=4e140981-4ab3-41a2-a2fb-26b1287beb87 ro quiet splash noefi video=efifb</span>
 initrd /boot/initrd.img-2.6.31-<span style="">14</span>-generic
<span style="">&#125;</span>
menuentry <span style="color: #933;">&quot;ubuntu-9.10-desktop-i386 single&quot;</span>
<span style="">&#123;</span>
 fakebios
 search --set -f /boot/vmlinuz-2.6.31-<span style="">14</span>-generic
 linux /boot/vmlinuz-2.6.31-<span style="">14</span>-generic root<span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">UUID=4e140981-4ab3-41a2-a2fb-26b1287beb87 ro noefi video=efifb single</span>
 initrd /boot/initrd.img-2.6.31-<span style="">14</span>-generic
<span style="">&#125;</span>
menuentry <span style="color: #933;">&quot;ubuntu-9.10-desktop-i386 text&quot;</span>
<span style="">&#123;</span>
 fakebios
 search --set -f /boot/vmlinuz-2.6.31-<span style="">14</span>-generic
 linux /boot/vmlinuz-2.6.31-<span style="">14</span>-generic root<span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">UUID=4e140981-4ab3-41a2-a2fb-26b1287beb87 ro noefi vga=normal</span>
 initrd /boot/initrd.img-2.6.31-<span style="">14</span>-generic
<span style="">&#125;</span>
menuentry <span style="color: #933;">&quot;Mac OS X&quot;</span>
<span style="">&#123;</span>
 search --set -f /usr/standalone/i386/boot.efi
 chainloader /usr/standalone/i386/boot.efi
<span style="">&#125;</span>
menuentry <span style="color: #933;">&quot;CD&quot;</span>
<span style="">&#123;</span>
 appleloader CD
<span style="">&#125;</span>
menuentry <span style="color: #933;">&quot;mbr&quot;</span>
<span style="">&#123;</span>
 appleloader HD
<span style="">&#125;</span>
menuentry <span style="color: #933;">&quot;reboot&quot;</span>
<span style="">&#123;</span>
 reboot
<span style="">&#125;</span></pre></div></div>

<p>You have to change the root UUID to the one the Ubuntu installer will assign to your hard disk after installation. Just check the fstab file when the installation has finished. The first entry boots Linux with a splash image enabled. The second one is for the single user mode in the case something went wrong. Please note the <strong>video=efifb</strong> option, which enables the graphical mode in the boot phase.</p>
<h2>Installing Ubuntu</h2>
<p>Most of the installation process is straight forward and doesn't need any special attention. Download the version of your choice from one of the mirrors, burn it on CD and start the installation. You can select the CD as boot medium by pressing <code class="key">Alt</code> when your Mac starts. When the installer ask for the partition scheme, you have to switch to "manual choice". Select the DISK1S5 (your what it is in your case) as the root / partition and change the filesystem type to ext3. Also remember the path to the system partition, cause you will need it later again. Select the swap partition and change its type to swap. Proceed with the rest of the installation until the last dialog. There select "advanced settings" and change the boot loader target from <code class="path">hd0</code> to <code class="path">/dev/sdXX</code>, where you replace XX to the path you used previously in the partition tool.</p>
<p>If all went right you should be able to select the LINUXBOOT partition by pressing <code class="key">Alt</code> when your Mac starts. After that Grub2 should shows up, you will be able to boot into your freshly installed Ubuntu.</p>
<h2>Conclusion</h2>
<p>In this post I showed how to easily add the possibility to boot Linux on your MacBook Pro. With the external USB hard disk solution, no internal valuable space is wasted. Of course the speed isn't the same as if the OS would be installed on the internal drive, but for testing software on different operation systems this is satisfactory. To increase the speed a little bit more, an external FireWire hard disk could be used.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.64k-tec.de/2010/04/installing-linux-on-a-usb-hard-disk-for-the-macbook-pro/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>FRITZ!Box tuning part 2: Access your home network with OpenVPN</title>
		<link>http://www.64k-tec.de/2010/02/fritzbox-tuning-part-2-access-your-home-network-with-openvpn/</link>
		<comments>http://www.64k-tec.de/2010/02/fritzbox-tuning-part-2-access-your-home-network-with-openvpn/#comments</comments>
		<pubDate>Tue, 02 Feb 2010 18:38:47 +0000</pubDate>
		<dc:creator>cp</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[Root]]></category>
		<category><![CDATA[administration]]></category>
		<category><![CDATA[communication]]></category>
		<category><![CDATA[FritzBox]]></category>
		<category><![CDATA[Gentoo]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[OpenVPN]]></category>
		<category><![CDATA[PKI]]></category>
		<category><![CDATA[remote access]]></category>
		<category><![CDATA[VPN]]></category>

		<guid isPermaLink="false">http://www.64k-tec.de/?p=379</guid>
		<description><![CDATA[AVM has built a VPN server into the FRITZ!Box, why should I use some other software for this job, you may ask. The reason is quite simple: the build in one is a piece of closed source software written by AVM and there is only one official client which could be used to connect to [...]]]></description>
			<content:encoded><![CDATA[<p>AVM has built a VPN server into the FRITZ!Box, why should I use some other software for this job, you may ask. The reason is quite simple: the build in one is a piece of closed source software written by AVM and there is only one official client which could be used to connect to it, the FRITZ!VPN software. This client software is only available for the Windows operation system family and so by no means anything useful to me. I'm pretty sure they are using some official protocol like <a href="http://en.wikipedia.org/wiki/IPsec" target="_blank">IPSec</a>, so it might be possible to connect to the FRITZ!Box with other clients as well, but that's something I didn't want to try. <a href="http://openvpn.net" target="_blank">OpenVPN</a> on the other side is a rock solid open source software which could be used from many popular OS's these days. Even graphical clients, like <a href="http://code.google.com/p/tunnelblick/" target="_blank">TunnelBlick</a> for Mac OS X, are available. So here comes the second article of the FRITZ!Box tuning <a href="/?s=FRITZ!Box+tuning">series</a>, which will explain how to convert your FRITZ!Box into a OpenVPN server, where any number of clients can concurrently be connected. I highly recommend to read the <a href="http://www.64k-tec.de/2010/01/fritzbox-tuning-part-1-enable-remote-access-over-ssh/">first part</a> of this series, because this post is build on top of the stuff done there. This count especially for the filesystem layout on the usbstick and the way additional software is started. Also in the following it will be helpful to have ssh access to the FRITZ!Box all the time. As already written in the first part, there is no guarantee that the information presented here will work on your side or that I'm responsible for anything happen to your FRITZ!Box. In preparation of the following you need access to a second OpenVPN installation which will be used to create all necessary certificates and keys and which could be used to test the installation afterward. I'm using a Gentoo Linux host where you could install OpenVPN simply by executing <code>emerge openvpn</code>. Make sure you have the <strong>examples</strong> USE flag set to get all the helper scripts which make the life much more easier.</p>
<h2>The agony of choice</h2>
<p>OpenVPN could be configured in many different ways. So first of all we have to decide which features of OpenVPN we will use. In its simplest variant OpenVPN could be used with one preshared static key. The advantage of this setup type is the easy configuration. The disadvantage is that only one client could be connected at the time. That is not what we want, so we will configure our setup to be using a <a href="http://en.wikipedia.org/wiki/Public_key_infrastructure" target="_blank">Public Key Infrastructure</a> (PKI). This allows more than one client to be connected at the time and it is possible to mark single keys invalid without affecting other client keys. The second question which has to be answered is, if we want use routing or bridging in our setup. Again, routing is simpler to set up and also a little bit faster than bridging. Bridging on the other side allows the tunneling of non IP protocols such as IPX, tunnel all the IP broadcast and make it possible to use the same subnet on the client side as on the server-side. Especially the last point is a nice feature as with routing all hosts on the server-side needs a routing table entry to find the connected clients. But my main reason for preferring bridging over routing is the broadcast feature of the first one. In my home network works a NAS station as a file server. This includes of course simple filesystem sharing with AFP and NFS, but also serves this box audio data with the <a href="http://en.wikipedia.org/wiki/Digital_Audio_Access_Protocol" target="_blank">Digital Audio Access Protocol</a> (DAAP). DAAP is used by Apple in iTunes to share music with other clients in the network and that is what my NAS station does. This protocol, as well AFP, using broadcast messages (ZeroConf) to find some potential clients. So now it should be clear why I want bridging, it allows me to hear music or to simply connect to my file station without any interaction.</p>
<h2>Building up a PKI</h2>
<p>To create all necessary certificates and keys we are using the <em>easy-rsa</em> scripts from OpenVPN. They are located under <code class="path">/usr/share/openvpn/easy-rsa</code>. First we change the <code class="path">vars</code> file. On the bottom of the file are personal information defined which should be changed to fit to your environment. The entries looking as follow on my side (with a pseudo email address).</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;">export KEY_COUNTRY<span style="color: #000066; font-weight:bold;">=</span><span style="color: #933;">&quot;DE&quot;</span>
export KEY_PROVINCE<span style="color: #000066; font-weight:bold;">=</span><span style="color: #933;">&quot;Sachsen&quot;</span>
export KEY_CITY<span style="color: #000066; font-weight:bold;">=</span><span style="color: #933;">&quot;Dresden&quot;</span>
export KEY_ORG<span style="color: #000066; font-weight:bold;">=</span><span style="color: #933;">&quot;64k&quot;</span>
export KEY_EMAIL<span style="color: #000066; font-weight:bold;">=</span><span style="color: #933;">&quot;you@yourdomain.org&quot;</span></pre></div></div>

<p>You could also increase the <strong>KEY_SIZE</strong> from 1024 to 2048 within that file. This should make your keys unbreakable for the next few <span style="text-decoration: line-through;">decades</span> years. Now we are ready to create the master-key and the master certificate of the Certificate Authority (CA) by executing:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">source</span> vars
.<span style="color: #000000; font-weight: bold;">/</span>clean-all
.<span style="color: #000000; font-weight: bold;">/</span>build-ca</pre></div></div>

<p>Please be aware that this will delete all previously created keys. Answering all questions with the default values should be sufficient. Next the key for the server has to be created.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">.<span style="color: #000000; font-weight: bold;">/</span>build-key-server server</pre></div></div>

<p>You can again accept all default values. A challenge password is not necessary, but you have to sign the certificate. Now its time for our first client key and certificate. You could the following repeat again and again, for every new client you want allow to access the OpenVPN server.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">.<span style="color: #000000; font-weight: bold;">/</span>build-key client</pre></div></div>

<p>Again, don't forget to sign the key. If you ever have to mark a client certificate invalid you could do it with the following command:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">.<span style="color: #000000; font-weight: bold;">/</span>revoke-full client</pre></div></div>

<p>This will create or update a Certificate Revocation List (CRL)<em> </em> file which will be later used by the server to verify the certificate integrity of a connecting client. For now we create an empty one with</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">KEY_CN</span>=<span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #007800;">KEY_OU</span>=<span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #007800;">KEY_NAME</span>=<span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #007800;">$OPENSSL</span> ca <span style="color: #660033;">-gencrl</span> <span style="color: #660033;">-out</span> keys<span style="color: #000000; font-weight: bold;">/</span>crl.pem <span style="color: #660033;">-config</span> <span style="color: #007800;">$KEY_CONFIG</span></pre></div></div>

<p>The last step in this key building marathon is to create a <a href="http://en.wikipedia.org/wiki/Diffie%E2%80%93Hellman_key_exchange" target="_blank">Diffie-Hellman</a> key. This key will be used to initiate the secure channel between the two parties. Its created by:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">.<span style="color: #000000; font-weight: bold;">/</span>build-dh</pre></div></div>

<h2>Creating the server and client configuration</h2>
<p>We start with the configuration of the server:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># set the path to the tap device</span>
dev tap
dev-node <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>tap0
mssfix
tun-mtu <span style="color: #000000;">1500</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># TCP or UDP server?</span>
proto udp
port <span style="color: #000000;">1194</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># CA and key files</span>
ca <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>media<span style="color: #000000; font-weight: bold;">/</span>ftp<span style="color: #000000; font-weight: bold;">/</span>FLASH-DISK-01<span style="color: #000000; font-weight: bold;">/</span>addons<span style="color: #000000; font-weight: bold;">/</span>openvpn<span style="color: #000000; font-weight: bold;">/</span>keys<span style="color: #000000; font-weight: bold;">/</span>ca.crt
cert <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>media<span style="color: #000000; font-weight: bold;">/</span>ftp<span style="color: #000000; font-weight: bold;">/</span>FLASH-DISK-01<span style="color: #000000; font-weight: bold;">/</span>addons<span style="color: #000000; font-weight: bold;">/</span>openvpn<span style="color: #000000; font-weight: bold;">/</span>keys<span style="color: #000000; font-weight: bold;">/</span>server.crt
key <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>media<span style="color: #000000; font-weight: bold;">/</span>ftp<span style="color: #000000; font-weight: bold;">/</span>FLASH-DISK-01<span style="color: #000000; font-weight: bold;">/</span>addons<span style="color: #000000; font-weight: bold;">/</span>openvpn<span style="color: #000000; font-weight: bold;">/</span>keys<span style="color: #000000; font-weight: bold;">/</span>server.key
crl-verify <span style="color: #000000; font-weight: bold;">/</span>keys<span style="color: #000000; font-weight: bold;">/</span>crl.pem <span style="color: #666666; font-style: italic;"># this is opened after the chroot</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Diffie hellman parameters</span>
<span style="color: #c20cb9; font-weight: bold;">dh</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>media<span style="color: #000000; font-weight: bold;">/</span>ftp<span style="color: #000000; font-weight: bold;">/</span>FLASH-DISK-01<span style="color: #000000; font-weight: bold;">/</span>addons<span style="color: #000000; font-weight: bold;">/</span>openvpn<span style="color: #000000; font-weight: bold;">/</span>keys<span style="color: #000000; font-weight: bold;">/</span>dh1024.pem
&nbsp;
<span style="color: #666666; font-style: italic;"># bridge setup</span>
server-bridge 192.168.220.1 255.255.255.0 192.168.220.50 192.168.220.99
mode server
tls-server
push <span style="color: #ff0000;">&quot;dhcp-option DNS 192.168.220.1&quot;</span>
&nbsp;
ifconfig-pool-persist ipp.txt
client-to-client
&nbsp;
<span style="color: #666666; font-style: italic;"># compression?</span>
comp-lzo
&nbsp;
<span style="color: #666666; font-style: italic;"># The maximum number of concurrently connected clients we want to</span>
<span style="color: #666666; font-style: italic;"># allow.</span>
max-clients <span style="color: #000000;">20</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># It's a good idea to reduce the OpenVPN daemon's privileges after</span>
<span style="color: #666666; font-style: italic;"># initialization.</span>
user nobody
group nobody
&nbsp;
<span style="color: #666666; font-style: italic;"># Put openvpn in a jail.</span>
<span style="color: #c20cb9; font-weight: bold;">chroot</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>media<span style="color: #000000; font-weight: bold;">/</span>ftp<span style="color: #000000; font-weight: bold;">/</span>FLASH-DISK-01<span style="color: #000000; font-weight: bold;">/</span>addons<span style="color: #000000; font-weight: bold;">/</span>openvpn
&nbsp;
<span style="color: #666666; font-style: italic;"># The persist options will try to avoid accessing certain resources on</span>
<span style="color: #666666; font-style: italic;"># restart that may no longer be accessible because of the privilege</span>
<span style="color: #666666; font-style: italic;"># downgrade.</span>
persist-key
persist-tun
&nbsp;
<span style="color: #666666; font-style: italic;"># where to log</span>
log-append <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>media<span style="color: #000000; font-weight: bold;">/</span>ftp<span style="color: #000000; font-weight: bold;">/</span>FLASH-DISK-01<span style="color: #000000; font-weight: bold;">/</span>addons<span style="color: #000000; font-weight: bold;">/</span>openvpn<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>openvpn.log
&nbsp;
<span style="color: #666666; font-style: italic;"># verbose level for debugging</span>
;verb <span style="color: #000000;">4</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># make sure the connection is kept alive</span>
keepalive <span style="color: #000000;">10</span> <span style="color: #000000;">120</span></pre></div></div>

<p>For bridged mode it is essential that OpenVPN uses a TAP device and not the TUN device mode (see <a href="http://en.wikipedia.org/wiki/TUN/TAP" target="_blank">here</a> for the reason). We use UDP as the transport protocol and enable compression. Also we want that OpenVPN drops its privileges after the initialization and chroot into a jail to make it a little bit more secure. As the subnet for clients 192.168.220.0/24 is used. That is the same as my internal network uses. OpenVPN is allowed to use addresses ranging from 192.168.220.50 to 192.168.220.99. You have to make sure that the FRITZ!Box (or any other DHCP server in your network) doesn't serve addresses from that range. Of course you could change some of the settings to your needs, but then you have to make sure they match the configuration of the client.</p>
<p>Next we create the client configuration, which looks as follow:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># Specify that we are a client and that we will be pulling certain</span>
<span style="color: #666666; font-style: italic;"># config file directives from the server.</span>
client
&nbsp;
<span style="color: #666666; font-style: italic;"># The hostname/IP and port of the server.</span>
remote xtestx.dyndns.org <span style="color: #000000;">1194</span>
&nbsp;
proto udp
dev tap
&nbsp;
pull
&nbsp;
mssfix
tun-mtu <span style="color: #000000;">1500</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># SSL/TLS parms.</span>
tls-client
ca keys<span style="color: #000000; font-weight: bold;">/</span>ca.crt
cert keys<span style="color: #000000; font-weight: bold;">/</span>client.crt
key keys<span style="color: #000000; font-weight: bold;">/</span>client.key
&nbsp;
ns-cert-type server
&nbsp;
<span style="color: #666666; font-style: italic;"># Keep trying indefinitely to resolve the host name of the OpenVPN</span>
<span style="color: #666666; font-style: italic;"># server. Very useful on machines which are not permanently connected</span>
<span style="color: #666666; font-style: italic;"># to the Internet such as laptops.</span>
resolv-retry infinite
&nbsp;
<span style="color: #666666; font-style: italic;"># Don't enable this; It must be disabled for iTunes to find the iTunes</span>
<span style="color: #666666; font-style: italic;"># server and for AFP broadcast in general.</span>
<span style="color: #666666; font-style: italic;">#nobind</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Downgrade privileges after initialization (non-Windows only)</span>
user nobody
group nobody
&nbsp;
<span style="color: #666666; font-style: italic;"># Try to preserve some state across restarts.</span>
persist-key
persist-tun
&nbsp;
<span style="color: #666666; font-style: italic;"># Enable compression on the VPN link.</span>
comp-lzo
&nbsp;
<span style="color: #666666; font-style: italic;"># debug level</span>
;verb <span style="color: #000000;">4</span>
&nbsp;
mute-replay-warnings
mute <span style="color: #000000;">20</span></pre></div></div>

<p>You have to change the <em>remote</em> hostname to your needs. You may also add the full path to the certificates and keys depending on your client OpenVPN installation.</p>
<p>Next we pack all files up for the server and the client respectively. The server needs the following one:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">server.conf
keys<span style="color: #000000; font-weight: bold;">/</span>ca.crt
keys<span style="color: #000000; font-weight: bold;">/</span>crl.pem
keys<span style="color: #000000; font-weight: bold;">/</span>dh1024.pem
keys<span style="color: #000000; font-weight: bold;">/</span>server.crt
keys<span style="color: #000000; font-weight: bold;">/</span>server.key</pre></div></div>

<p>The client needs this one:<a name="client_pack"></a></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">client.conf
keys<span style="color: #000000; font-weight: bold;">/</span>ca.crt
keys<span style="color: #000000; font-weight: bold;">/</span>client.crt
keys<span style="color: #000000; font-weight: bold;">/</span>client.key
keys<span style="color: #000000; font-weight: bold;">/</span>server.crt</pre></div></div>

<h2>Customizing the FRITZ!Box</h2>
<p>Connect to your FRITZ!Box and copy all the server files to the usbstick. I created a directory <code class="path">openvpn</code> under the <code class="path">/var/media/ftp/FLASH-DISK-01/addons</code> path. Next we need the OpenVPN binary for the FRITZ!Box. You can get it <a href="http://www.cswpro.de/_files/openvpn_kernel_2_6.zip">here</a>. Unpack the file and copy the openvpn binary to <code class="path">/var/media/ftp/FLASH-DISK-01/addons/bin</code> on the FRITZ!Box. Make sure the file mode has the executable bit set for the user. All files are now on the right places, so we can adjust our start script. Add the following code to the <code class="cmd">startup.sh</code> file.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># Add a nobody user</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">'nobody:x:65534:65534:nobody:/:/bin/false'</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">passwd</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Add some groups</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">'root:x:0:'</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>group
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">'nobody:x:65534:'</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>group
&nbsp;
<span style="color: #666666; font-style: italic;"># Create a tap device for openvpn</span>
<span style="color: #c20cb9; font-weight: bold;">mknod</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>tap0 c <span style="color: #000000;">10</span> <span style="color: #000000;">200</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Start openvpn</span>
<span style="color: #800000;">${BASE}</span><span style="color: #000000; font-weight: bold;">/</span>openvpn<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>openvpn <span style="color: #660033;">--config</span> <span style="color: #800000;">${BASE}</span><span style="color: #000000; font-weight: bold;">/</span>openvpn<span style="color: #000000; font-weight: bold;">/</span>server.conf <span style="color: #660033;">--daemon</span></pre></div></div>

<p>As you see, we add a new <em>nobody</em> user to the Linux system. Then the device node for the TAP device is created and at the end the OpenVPN server is started. As we using the bridged setup, we have to add the new device to a bridge. Fortunately we haven't to create one, cause the FRITZ!Box itself is working in bridged mode. You can confirm this by executing:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">brctl show lan</pre></div></div>

<p>To let the system automatically add our TAP device to the <em>lan</em> bridge, we change the internal FRITZ!Box configuration. Edit the <code class="path">/var/flush/ar7.cfg</code> file with nvi and search for the string <em>brinterfaces</em>. There should be one section with the name <em>lan</em>. Simply add the new <em>tap0</em> interface to the interfaces value. The section should then look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;">brinterfaces <span style="">&#123;</span>
     <span style="color: #000099;">name</span> <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;lan&quot;</span><span style="color: #666666; font-style: italic;">;</span>
     <span style="color: #000099;">dhcp</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> no</span><span style="color: #666666; font-style: italic;">;</span>
     <span style="color: #000099;">ipaddr</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> 192.168.220.1</span><span style="color: #666666; font-style: italic;">;</span>
     <span style="color: #000099;">netmask</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> 255.255.255.0</span><span style="color: #666666; font-style: italic;">;</span>
     <span style="color: #000099;">dstipaddr</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> 0.0.0.0</span><span style="color: #666666; font-style: italic;">;</span>
     <span style="color: #000099;">interfaces</span> <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;eth0&quot;</span>, <span style="color: #933;">&quot;ath0&quot;</span>, <span style="color: #933;">&quot;tap0&quot;</span>, <span style="color: #933;">&quot;wdsup1&quot;</span>, <span style="color: #933;">&quot;wdsdw1&quot;</span>,
                  <span style="color: #933;">&quot;wdsdw2&quot;</span>, <span style="color: #933;">&quot;wdsdw3&quot;</span>, <span style="color: #933;">&quot;wdsdw4&quot;</span><span style="color: #666666; font-style: italic;">;</span>
     <span style="color: #000099;">dhcpenabled</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> yes</span><span style="color: #666666; font-style: italic;">;</span>
     <span style="color: #000099;">dhcpstart</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> 192.168.220.100</span><span style="color: #666666; font-style: italic;">;</span>
     <span style="color: #000099;">dhcpend</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> 192.168.220.200</span><span style="color: #666666; font-style: italic;">;</span>
<span style="">&#125;</span></pre></div></div>

<p>Now, as soon the tap0 interface is created it will be added to the bridge. The last important point in the server setup is to change the internal firewall to allow connections to port 1194 from the outside. Search for <em>forwardrules</em> in the <code class="path">ar7.cfg</code> file and add this new rule:</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;"><span style="color: #000099;">forwardrules</span> <span style="color: #000066; font-weight:bold;">=</span>
               <span style="color: #933;">&quot;tcp 0.0.0.0:7777 0.0.0.0:22 0 # SSH-Server&quot;</span>,
               <span style="color: #933;">&quot;udp 0.0.0.0:1194 0.0.0.0:1194 0 # VPN-Server&quot;</span><span style="color: #666666; font-style: italic;">;</span></pre></div></div>

<p>Thats all for the server. A reboot of the FRITZ!Box should start the new OpenVPN server. If you have trouble you should manually start the OpenVPN server and increase the debugging level, as shown in the above configuration with the keyword <em>verb</em>.</p>
<h2>Setting up the client</h2>
<p>On the client side we need the files we packed <a href="#client_pack">above</a>. On Gentoo the OpenVPN configuration is located at <code class="path">/etc/openvpn</code>. Copy the configuration, the certificates and the key file to that place. The OpenVPN start script of Gentoo looks for the configuration file, based on the start script name. So we have to create a link like this:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>openvpn
<span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> client.conf openvpn.conf</pre></div></div>

<p>By the way, this lets you configure more than one OpenVPN connection at the time. Just create a link in <code class="path">/etc/init.d</code> with the new configuration name and link it to the <code class="path">openvpn</code> start script.</p>
<p>To make a first attempt to start the OpenVPN connection type</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>openvpn start</pre></div></div>

<p>If  all goes well you should have a new device <em>tap0</em> when you  execute <code>ifconfig</code>. Also there should be a route set,  which point to the tap0  device when the 192.168.220.0/24 subnet is the  target. Of course now you should be able to connect to any host in your  home network by the IP. I didn't experiment enough with the pushing of  the name server from the OpenVPN server, instead I just added the  FRITZ!Box as an additionally name server to my <code class="path">/etc/resolv.conf</code>. So here is room for further experiments.</p>
<p>To let the OpenVPN client start at boot time add it to the default runlevel by executing:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">rc-update add openvpn default</pre></div></div>

<p>Also note that with the above configuration the client always try to  reconnect to the server, even if the FRITZ!Box is rebooted, which is a nice feature.</p>
<h2>Conclusion</h2>
<p>This setup allows you to connect to your home network in a very secure way without loosing any functionality. You are able to browse network shares on the local network or using services like DAAP without any further interaction.  The public key infrastructure make this setup a candidate for small business installations. If an employee leave the company his certificate is simply revoked without affecting the access of other employees.</p>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 1754px; width: 1px; height: 1px; overflow: hidden;"><a href="http://www.cswpro.de/Howto/FritzBox_OpenVPN.aspx" target="_blank">http://wwww.cswpro.de</a></div>
]]></content:encoded>
			<wfw:commentRss>http://www.64k-tec.de/2010/02/fritzbox-tuning-part-2-access-your-home-network-with-openvpn/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>FRITZ!Box tuning part 1: Enable remote access over ssh</title>
		<link>http://www.64k-tec.de/2010/01/fritzbox-tuning-part-1-enable-remote-access-over-ssh/</link>
		<comments>http://www.64k-tec.de/2010/01/fritzbox-tuning-part-1-enable-remote-access-over-ssh/#comments</comments>
		<pubDate>Sat, 23 Jan 2010 10:44:17 +0000</pubDate>
		<dc:creator>cp</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[Root]]></category>
		<category><![CDATA[administration]]></category>
		<category><![CDATA[communication]]></category>
		<category><![CDATA[FritzBox]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[remote access]]></category>
		<category><![CDATA[ssh]]></category>
		<category><![CDATA[telnet]]></category>

		<guid isPermaLink="false">http://www.64k-tec.de/?p=257</guid>
		<description><![CDATA[Recently I changed my Internet service provider to Kabel Deutschland which offers some really good bandwidth for a reasonable price. You get 32 MBit in the download direction and 2 Mbit in the upload direction. Additionally to this you can order a FRITZ!Box 7270 which allows you to use VoIP for the phone part. As [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I changed my Internet service provider to Kabel Deutschland which offers some really good bandwidth for a reasonable price. You get 32 MBit in the download direction and 2 Mbit in the upload direction. Additionally to this you can order a FRITZ!Box 7270 which allows you to use VoIP for the phone part. As I always try to maximize the usage of new hardware I started to explore what is possible with this combination. In this post I will explain how you get access to your FRITZ!Box using ssh. Following this post, some articles about how you can turn the FRITZ!Box into a OpenVPN server and how you can use the VoIP access point remotely from any computer having a VoIP software installed, will be done. As I said the hardware used is a FRITZ!Box Fon WLAN 7270 with the firmware 54/74.04.80 from 2009/12/15 which is an official one from AVM. Other firmware versions may work also, but I haven't tested that. The following topics are all for advanced user. So if you aren't in touch with Linux or start asking what the hell is vi and how get I out of it, stop reading now. All the information in this and the following posts are based on several websites I found in the Internet. Mainly this are some forum entries at <a href="http://www.ip-phone-forum.de" target="_blank">http://www.ip-phone-forum.de</a>, the series about the FRITZ!Box at <a href="http://www.tecchannel.de/server/extra/432803/tuning_hacks_fritzbox_fritz_box_erweiterungen_ftp_telnet/" target="_blank">http://www.tecchannel.de</a>, the posts on <a href="http://www.teamarbyte.de/ssh-fritzbox.html" target="_blank">http://www.teamarbyte.de</a>, the blog at <a href="http://www.realriot.de/category/hardware/fritzbox/" target="_blank">http://www.realriot.de</a> and this article at <a href="http://www.cswpro.de/Howto/FritzBox_OpenVPN.aspx" target="_blank">http://www.cswpro.de</a>. So thanks to all the people for sharing this kind of information. Before we start some words of caution: It's easily possible to render the FRITZ!Box unusable. So there is no warranty of any kind if you do some of the things mentioned in this blog. Also I'm not responsible for anything happen to your FRITZ!Box or the Internet connection. After all making a backup of your current configuration might be a good idea.</p>
<h2>Preparing the FRITZ!Box</h2>
<p>First of all you should register an account at <a href="http://www.dyndns.com" target="_blank">http://www.dyndns.com</a> or any other service for dynamic IP resolution. You can then add this information to the "DynamicDNS" tab of the Internet settings in the FRITZ!Box web frontend. This will allow you to connect to your FRITZ!Box without knowing the IP after a reconnect. Lets use us <em>xtestx.dyndns.org</em> in the following examples. Next you need telnet access to the FRITZ!Box to make the initial configuration for the ssh server. Enabling telnet is as simple as calling <strong><tt>#96*7*</tt></strong> with a local connected phone. To disable the telnet daemon later you call <strong><tt>#96*8*</tt></strong>. Now you need a usbstick where all the software will be installed on and which have to be connected to the FRITZ!Box all the time. In principle the size doesn't matter, around 5 MBytes free space should be enough. Time to connect to the FRITZ!Box for the first time. A simple <code class="cmd">telnet fritz.box</code> should do it.</p>
<h2>Installation and configuration of the ssh server</h2>
<p>For the ssh server software <a href="http://matt.ucc.asn.au/dropbear/dropbear.html" target="_blank">dropbear</a> is used. You can get a prepared version for the FRITZ!Box from the spblinux server.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>tmp
<span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>www.spblinux.de<span style="color: #000000; font-weight: bold;">/</span>fbox.new<span style="color: #000000; font-weight: bold;">/</span>cfg_dropbear
<span style="color: #c20cb9; font-weight: bold;">chmod</span> u+x cfg_dropbear</pre></div></div>

<p>After downloading, the server has to be installed on the usbstick by executing</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">.<span style="color: #000000; font-weight: bold;">/</span>cfg_dropbear usb_install</pre></div></div>

<p>In my case the software is installed into <code class="path">/var/media/ftp/FLASH-DISK-01/addons</code>. Now we will create a host key which will be reused even after a reboot of the FRITZ!Box.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>media<span style="color: #000000; font-weight: bold;">/</span>ftp<span style="color: #000000; font-weight: bold;">/</span>FLASH-DISK-01<span style="color: #000000; font-weight: bold;">/</span>addons
dropbear<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>dropbearkey <span style="color: #660033;">-t</span> rsa <span style="color: #660033;">-f</span> dropbear<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>sshd_rsa_host_key</pre></div></div>

<p>The FRITZ!Box has initial no root password entry. We have to create one and save the password hash for later usage.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">passwd</span>
<span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">passwd</span></pre></div></div>

<p>You have to note the part between <em>root:</em> and the next <em>colon</em>.</p>
<h2>Putting all together</h2>
<p>The initial starting point for all modifications on the FRITZ!Box is a file called <code class="path">/var/flash/debug.cfg</code>. Its executed on every boot after all the other services are started. We will use it only to start a script which is located on the usbstick. This makes sure that even after a firmware upgrade our changes are not lost. The content looks like the following:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># execute the start script which is on the usb stick</span>
<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>media<span style="color: #000000; font-weight: bold;">/</span>ftp<span style="color: #000000; font-weight: bold;">/</span>FLASH-DISK-01<span style="color: #000000; font-weight: bold;">/</span>addons<span style="color: #000000; font-weight: bold;">/</span>startup.sh</pre></div></div>

<p>Please note that you have to use the <code>nvi</code> to edit files on the flash device from the FRITZ!Box, cause all files there are marked as non regular. The <code class="cmd">startup.sh</code> will do all the work necessary for preparing and starting the ssh server. The content is:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
<span style="color: #666666; font-style: italic;"># whats the base usb directory</span>
<span style="color: #007800;">BASE</span>=<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>media<span style="color: #000000; font-weight: bold;">/</span>ftp<span style="color: #000000; font-weight: bold;">/</span>FLASH-DISK-01<span style="color: #000000; font-weight: bold;">/</span>addons
&nbsp;
<span style="color: #666666; font-style: italic;"># change to a temporary directory</span>
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>tmp
&nbsp;
<span style="color: #666666; font-style: italic;"># install and start dropbear with our host key</span>
<span style="color: #800000;">${BASE}</span><span style="color: #000000; font-weight: bold;">/</span>cfg_dropbear usb_install
<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>dropbear <span style="color: #660033;">-E</span> <span style="color: #660033;">-r</span> <span style="color: #800000;">${BASE}</span><span style="color: #000000; font-weight: bold;">/</span>dropbear<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>sshd_rsa_host_key
&nbsp;
<span style="color: #666666; font-style: italic;"># set passwords</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">'root:XXXXXX:0:0:root:/var/tmp/:/bin/sh'</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">passwd</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">'ftpuser:any:1000:0:ftp user:/var/media/ftp:/bin/sh'</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">passwd</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># add fritz box itself in resolv.conf to resolv dhcp attached machines in your network</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;nameserver 192.168.220.1&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>resolv.conf</pre></div></div>

<p>You have to replace XXXXXX by the password hash you created above. In my case the network is in the 192.168.220.0/24 subnet and the FRITZ!Box has the IP 192.168.220.1. You have to adjust the name server entry to your environment. After a reboot which could be initiated with <code>reboot</code> you should be able to access your FRITZ!Box over ssh.</p>
<p>To allow connections from the outside of your home you need to change the forward rules of the internal FRITZ!Box firewall. Unfortunately you can't add this rule using the web frontend cause it isn't allowed to add rules which targeting the FRITZ!Box itself. Most of the settings for the FRITZ!Box configuration are located in a file called <code class="path">/var/flash/ar7.cfg</code>. Use nvi to edit it and search for the string <strong>forwardrules</strong>. If this string is missing you could temporary create a rule in the web frontend, which will you later remove again. You have to change the line so that it looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;"><span style="color: #000099;">forwardrules</span> <span style="color: #000066; font-weight:bold;">=</span>
               <span style="color: #933;">&quot;tcp 0.0.0.0:7777 0.0.0.0:22 0 # SSH-Server&quot;</span><span style="color: #666666; font-style: italic;">;</span></pre></div></div>

<p>Here the connection port is 7777, but of course could you use any valid port number. You could also add more rules by separating them with a comma. To make the configuration change happen the execution of <code class="cmd">ar7cfgchanged</code> is sufficient.</p>
<h2>Conclusion</h2>
<p>With this setup its possible to connect to the FRITZ!Box with the very secure ssh protocol from inside of your home environment and from the outside. This makes it easily possible to change parameters without manually starting the telnet daemon which is in addition very insecure. Don't forget to remove any temporary rules from the ar7.cfg file and to disable the telnet daemon with the procedure explained above. Stay tuned for the <a href="http://www.64k-tec.de/2010/02/fritzbox-tuning-part-2-access-your-home-network-with-openvpn/">next post</a> about going one step further and making the FRITZ!Box an OpenVPN connection point for your internal network.</p>
<h2>Update</h2>
<p>There is a new article about installing ssh on the FRITZ!Box. If you are interested have a look at <a href="http://www.64k-tec.de/2011/07/fritzbox-tuning-part-4-cross-building-and-installing-additional-applications/">this post</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.64k-tec.de/2010/01/fritzbox-tuning-part-1-enable-remote-access-over-ssh/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
	</channel>
</rss>

