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

<channel>
	<title>Voodoo Programming &#187; Script</title>
	<atom:link href="http://www.cneophytou.com/tag/script/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.cneophytou.com</link>
	<description>Things programmers do that they know shouldn&#039;t work but they try anyway, and which sometimes actually work, such as recompiling everything.</description>
	<lastBuildDate>Tue, 20 Oct 2009 13:54:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>Smooth SSH Passwordless Authentication</title>
		<link>http://www.cneophytou.com/2008/02/05/smooth-ssh-passwordless-authentication/</link>
		<comments>http://www.cneophytou.com/2008/02/05/smooth-ssh-passwordless-authentication/#comments</comments>
		<pubDate>Tue, 05 Feb 2008 14:36:17 +0000</pubDate>
		<dc:creator>Constantinos</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Terminal]]></category>
		<category><![CDATA[OS X]]></category>
		<category><![CDATA[Script]]></category>
		<category><![CDATA[SSH]]></category>
		<category><![CDATA[Unix]]></category>

		<guid isPermaLink="false">http://www.cneophytou.com/2008/02/05/smooth-ssh-passwordless-authentication/</guid>
		<description><![CDATA[This post first appeared on the Voodoo Finance blog which is maintained by my friend Constantinos Michael, and I&#8217;m recreating it here with some extensions so I can find the code more easily when I need it. Using computers remotely is a big part of what I do. Whether I&#8217;m at home and need to [...]]]></description>
			<content:encoded><![CDATA[This post first appeared on the <a href='http://cmichae.acm.jhu.edu/blog/2007/01/18/ssh-passwordless-authentication/'>Voodoo Finance</a> blog which is maintained by my friend <a href='http://cmichae.acm.jhu.edu/'>Constantinos Michael</a>, and I&#8217;m recreating it here with some extensions so I can find the code more easily when I need it.<br />
<br />
Using computers remotely is a big part of what I do. Whether I&#8217;m at home and need to connect to a computer in the lab, or in the lab or the road and need to connect to my home computer. The way I (and pretty much most other linux users) is through SSH. If you&#8217;ve ever had to open more than one ssh connection however, it gets old pretty quickly. First you need to remember the host (and potentially the port, if it&#8217;s not standard) of the machine you&#8217;re connecting to, and also your username on that machine. After those are typed in, you need to enter your password every time you initiate a new connection. Well, all of the above can be automated with a few quick keystrokes in the terminal.<br />
<span id="more-109"></span>
<br />
The first step is to generate an SSH key pair. This private / public key pair will be used to authenticate you on the target machine. As it&#8217;s using an RSA key pair, you can probably leave the passphrase empty as the attacker would first need access to your private key. If you&#8217;re really paranoid, you can type in an easy password (but you&#8217;ll need to type this password in every time you use the key). To generate this key, type the following in a terminal window:</p>


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



<p>
After this is done, you&#8217;re ready to install this key on any remote machine you wish to access. Before you do that however, I suggest setting up some aliases to the target machine so you don&#8217;t have to type the host and username every time you wish to log in. To do that, you need to edit (or create) a file called <code>~/.ssh/config</code>. In this file, you can enter a block of text for each host you wish to create an alias for. You can add as many hosts you want, just make sure there&#8217;s an empty line between each configuration. This is an example of what needs to go in this file:</p>


<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">host lab
user admin
HostName www.example.com
port 12345</pre></div></div>



<p>
There are many more options that can go in there, and it mostly depends on your setup. But for anything that you don&#8217;t need to specify in the ssh command line, you don&#8217;t need to add an option for in this file. For example with the text I provided above, when you type <code>ssh lab</code> in the command line, it will try to connect to <code>www.example.com</code> using the username <code>admin</code> on port <code>12345</code>. This would be equivalent to typing <code>ssh &#x61;&#x64;&#x6d;&#x69;&#x6e;&#x40;&#x77;&#x77;&#x77;&#x2e;&#x65;xample.com -oPort=12345</code>. Much easier, isn&#8217;t it?<br />
<br />
Now on to the juicy stuff. Create a script that will install your key on the remote machine. To do that, paste these instructions in the terminal:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">touch</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>ssh-install-key ;
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">chmod</span> a+<span style="color: #c20cb9; font-weight: bold;">w</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>ssh-install-key
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;cat ~/.ssh/id_rsa.pub | ssh <span style="color: #000099; font-weight: bold;">\$</span>{1} <span style="color: #000099; font-weight: bold;">\&quot;</span>cat - &gt;&gt; ~/.ssh/authorized_keys<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span> \
     <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>ssh-install-key
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">chmod</span> a-w+x <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>ssh-install-key</pre></div></div>



<p>
At this stage, you&#8217;re done with the setup. All you need to do is type</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">ssh-install-key lab</pre></div></div>



<p>
in the terminal window (assuming you&#8217;ve set up the above <code>config</code> file with a host called <code>lab</code>), enter  your password as many times as you&#8217;re prompted, and you&#8217;re done! Every subsequent time you wish to connect to this machine, all you need to do is type <code>ssh lab</code>, and you&#8217;re immediately connected, no questions asked! (Unless of course you provided a passphrase for your key pair, in which case you will be prompted for that password).]]></content:encoded>
			<wfw:commentRss>http://www.cneophytou.com/2008/02/05/smooth-ssh-passwordless-authentication/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Bandwidth throttling in OS X</title>
		<link>http://www.cneophytou.com/2008/01/19/bandwidth-throttling-in-os-x/</link>
		<comments>http://www.cneophytou.com/2008/01/19/bandwidth-throttling-in-os-x/#comments</comments>
		<pubDate>Sat, 19 Jan 2008 14:27:52 +0000</pubDate>
		<dc:creator>Constantinos</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[OS X]]></category>
		<category><![CDATA[Terminal]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[Script]]></category>
		<category><![CDATA[Unix]]></category>

		<guid isPermaLink="false">http://www.cneophytou.com/2008/01/19/bandwidth-throttling-in-os-x/</guid>
		<description><![CDATA[It&#8217;s been a while since my last post, and that&#8217;s because I&#8217;ve been busy with coursework, so I haven&#8217;t had time to mess around with OS X. However there was one feature I needed to figure out out of necessity if anything else. I have certain files I wish to freely share with some friends [...]]]></description>
			<content:encoded><![CDATA[It&#8217;s been a while since my last post, and that&#8217;s because I&#8217;ve been busy with coursework, so I haven&#8217;t had time to mess around with OS X. However there was one feature I needed to figure out out of necessity if anything else. I have certain files I wish to freely share with some friends of mine, and the easiest way for me to do that was put them on my local web server and serve them over http. The only problem with this approach, is that the university has a weekly data transfer limit of 5Gb per week during peak hours, those being between 6pm and midnight. Additionally, local traffic doesn&#8217;t count towards that limit, and if that limit is exceeded then my Internet would be blocked and limited to only the local network for the remainder of that week.<br />
<br />
Therefore, the solution I was looking for would not require me to turn off my web server (as I&#8217;d like to still access it locally), and would ideally simply limit the outgoing traffic automatically between those two times.<br />
<span id="more-105"></span>
<br />
One aspect that made this particular solution usable, was the fact that port 80 is firewalled from the external world. This means that if I want to run a web server on my local machine accessible from the outside, I have to do it on a different port. Therefore I use port 80 to access the web server locally, and port 8080 to access it from the outside. This gives me a dedicated point of entry for the traffic that I wish to limit the bandwidth.<br />
<br />
The solution is fairly simple, and involves only two tools: <code>cron</code>, for enabling and disabling the filter at specific times, and <code>ipfw</code> for actually setting up the filters. The idea is this: create a <code>pipe</code> using <code>ipfw</code> that limits outgoing traffic on port 8080 to a specified rate (let&#8217;s say 15KByte/s), and using a cron job add the pipe to my network interface at 6pm, and delete it at midnight. That&#8217;s it! Theoretically you only have to create the pipe once, but in order to have this survive across restarts, I added another cron job at 5:59pm that re-creates the pipe. The full contents of the crontab file (located at <code>/etc/crontab</code>) are as follows:<br />
</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># Set the bandwidth limit at 5:59pm</span>
<span style="color: #000000;">59</span> <span style="color: #000000;">17</span>	<span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span>	root	<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>ipfw pipe <span style="color: #000000;">1</span> config bw 15KByte<span style="color: #000000; font-weight: bold;">/</span>s
<span style="color: #666666; font-style: italic;"># Add the bandwidth limit to the specified port at 6:00pm</span>
<span style="color: #000000;">0</span> <span style="color: #000000;">18</span>	<span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span>	root	<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>ipfw add <span style="color: #000000;">1</span> pipe <span style="color: #000000;">1</span> src-port <span style="color: #000000;">8080</span>
<span style="color: #666666; font-style: italic;"># Lift the bandwidth limit at 12:00am</span>
<span style="color: #000000;">0</span> <span style="color: #000000;">0</span>	<span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span>	root	<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>ipfw delete <span style="color: #000000;">1</span></pre></div></div>



<p>
The problem with this is if the computer boots up or reboots after 6pm and before midnight, the filters will not be set. The solution is to use <code>anacron</code> for executing the ipfw commands, But as I rarely shut down or reboot my computer, it wasn&#8217;t worth it for me to make that happen. If I do make those modifications, I will post an update here. Also note that the ipfw commands need to be executed as root.<br />]]></content:encoded>
			<wfw:commentRss>http://www.cneophytou.com/2008/01/19/bandwidth-throttling-in-os-x/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
