<?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>Cranky Bit &#187; Open Source</title>
	<atom:link href="http://blog.crankybit.com/tag/open-source/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.crankybit.com</link>
	<description>Take a byte out of tech!</description>
	<lastBuildDate>Wed, 09 Mar 2011 17:23:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Avoiding the Password Prompt for SSH</title>
		<link>http://blog.crankybit.com/avoiding-the-password-prompt-for-ssh/</link>
		<comments>http://blog.crankybit.com/avoiding-the-password-prompt-for-ssh/#comments</comments>
		<pubDate>Wed, 15 Oct 2008 16:22:11 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[howto]]></category>

		<guid isPermaLink="false">http://blog.crankybit.com/?p=311</guid>
		<description><![CDATA[It&#8217;s handy to establish an SSH key between machines so that SSH-related commands don&#8217;t prompt you for a password. This is handy to quickly SSH into another machine, and it&#8217;s even more handy when setting up SSH commands in automated scripts. For instance, you may want to execute some rsync statements in a script that [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s handy to establish an SSH key between machines so that SSH-related commands don&#8217;t prompt you for a password. This is handy to quickly SSH into another machine, and it&#8217;s even more handy when setting up SSH commands in automated scripts. For instance, you may want to execute some rsync statements in a script that runs on a regular basis. It&#8217;s better to have an established SSH key between the two machines than to have a password embedded in the script.</p>
<p>I recently reinstalled the OS on one of my Macs, and I&#8217;ve got backup scripts on my CentOS Linux box that use rsync to back up some pertinent data, so I had to reestablish the SSH key between the machines and had a hard time remembering how to do it. So this time I&#8217;m documenting what I had to re-learn.</p>
<p>First of all, there&#8217;s a <a href="http://nixcraft.com/1196-post2.html" target="_blank">great post over at nixCraft</a> that basically explains how to do it. But allow me to explain more thoroughly, ahem, dumbed down to my level. </p>
<p>The key is remembering which machine is filling which role when you&#8217;re reading the instructions. I&#8217;ll call them the &#8220;Acting&#8221; machine&#8211;the one who is taking action and performing a command, let&#8217;s say an rsync command&#8211;and the &#8220;Target&#8221; machine&#8211;the one who is being acted upon. In my case, the Linux server is the acting machine performing the rsync command, and my Mac is the target.</p>
<p>The process is simple. On the &#8220;Target&#8221; machine, generate a key, and then give that key to the &#8220;Acting&#8221; machine, which effectively gives it &#8220;permission&#8221; to login without the need to supply username/password credentials.</p>
<p>So, from the &#8220;Target&#8221; machine, in this case, my Mac, type the following command:</p>
<p>ssh-keygen -t rsa</p>
<p>This will generate a couple files that serve as a key for accessing the Mac. The ssh-keygen command may ask you where to store the key and what password to use. Just hit enter to use the default path and a blank password.</p>
<p>Next, still from the &#8220;Target&#8221; machine (my Mac), type:</p>
<p>ssh <em>MyUsername@ActingServer</em> &#8221;mkdir .ssh&#8221;<br />
scp .ssh/id_rsa.pub <em>MyUsername@ActingServer</em>:.ssh/authorized_keys2</p>
<p>In the code above, <em>MyUsername@ActingServer</em> would be the username and address (for instance, perhaps the IP address) of the &#8220;Acting&#8221; machine, in my case, the Linux server. In the first line, you&#8217;re just creating the .ssh directory if it doesn&#8217;t exist. In the second line, you&#8217;re copying the key you generated from the &#8220;Target&#8221; machine to the &#8220;Acting&#8221; machine, or from the Mac to the Linux server.  Note that the scp command will ask for the password to the <em>MyUsername</em> account because it is connecting to that server to send it the key.</p>
<p>Voile. As if by magic, the &#8220;Acting&#8221; machine should now be able to SSH into the &#8220;Target&#8221; machine without a password prompt. Correspondingly, you should be able to perform rsync and other SSH commands without a password prompt. Please note, however, that <em>this is only a one-way key.</em><em> </em>We only gave my Linux server permission to access my Mac.</p>
<p><strong>What if I want my Mac to similarly login to the server without a password prompt?</strong> In that case, the Mac and the server have effectively switched roles; the Mac is now the &#8220;Acting&#8221; machine and the server is the &#8220;Target&#8221; machine, so we just have to repeat the process from the other direction. Generate a key from the server and send it to the Mac. At that point, both machines will be able to access each other without a password prompt. </p>
<p><strong>What if I have multiple &#8220;Targets&#8221; that the &#8220;Acting&#8221; machine will connect to?</strong> For instance, perhaps I have multiple Macs, and the Linux server is running scripts on all of them. When you&#8217;re sending the key to the &#8220;Acting&#8221; server with the scp command, use a different name for each key file, don&#8217;t overwrite the same file each time! So in the example code above, we&#8217;re sending the key as &#8220;authorized_keys2&#8243;. When repeating this process for multiple targets, send the keys as &#8220;authorized_keys3&#8243;, and so forth.</p>
<p>Hopefully this will clear up some confusion regarding this process.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.crankybit.com/avoiding-the-password-prompt-for-ssh/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>

