<?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; SSH</title>
	<atom:link href="http://www.cneophytou.com/tag/ssh/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>
	</channel>
</rss>
