<?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>Red Green Software &#187; shell</title>
	<atom:link href="http://www.red-green.com/category/shell/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.red-green.com</link>
	<description>We take stopped projects and get them going again.</description>
	<lastBuildDate>Sun, 05 Sep 2010 15:27:00 +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>Automatic SSH login using RSA/DSA keys</title>
		<link>http://www.red-green.com/2007/06/automatic-ssh-login-using-rsadsa-keys/</link>
		<comments>http://www.red-green.com/2007/06/automatic-ssh-login-using-rsadsa-keys/#comments</comments>
		<pubDate>Wed, 20 Jun 2007 20:28:26 +0000</pubDate>
		<dc:creator>stevet</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://www.red-green.com/2007/06/automatic-ssh-login-using-rsadsa-keys/</guid>
		<description><![CDATA[Creating the RSA Key ssh-keygen -t rsa This will create the id_rsa and id_rsa.pub files. The id_rsa.pub file located in ~/.ssh is your public key. Copy it to the system you want to automatically login to. See `man ssh-keygen` for more options. Why do I only show RSA keys? Because it&#39;s safer then the DSA [...]]]></description>
			<content:encoded><![CDATA[<h1>Creating the RSA Key</h1>

<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>This will create the id_rsa and id_rsa.pub files. The id_rsa.pub file located in ~/.ssh is your public key. Copy it to the system you want to automatically login to. See `man ssh-keygen` for more options. Why do I only show RSA keys? Because it&#39;s <a href="http://the.earth.li/~sgtatham/putty/0.53b/htmldoc/Chapter8.html#8.2.2" target="_blank" title="RSA Safer then DSA">safer then the DSA keys according to the putty developers (see section 8.2.2)</a> . I&#39;m sure that all the bugs in DSA have been fixed by now, including the key generation problems, but why take unnecessary risks?</p>
<h1>Public Key Adding Script</h1>

<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;"># September 23, 2003 (initial)</span>
<span style="color: #666666; font-style: italic;"># Updated August 23, 2006 (updated)</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Steve Thielemann</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># A script file to add ssh key</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># 1.) Verifies ~/.ssh directory exists, if not creates and</span>
<span style="color: #666666; font-style: italic;">#     fixes permissions.</span>
<span style="color: #666666; font-style: italic;"># 2.) Verifies ~/.ssh/authorized_keys exists, if not creates and</span>
<span style="color: #666666; font-style: italic;">#     fixes permissions.</span>
<span style="color: #666666; font-style: italic;"># 3.) Checks to see if ssh key is already present, if not adds to</span>
<span style="color: #666666; font-style: italic;">#     ~/.ssh/authorized_keys.</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># dependant on:  grep, touch, chmod, cut</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</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>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000; font-weight: bold;">&amp;</span>quot;I need the filename of a public key to add.<span style="color: #000000; font-weight: bold;">&amp;</span>quot;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000; font-weight: bold;">&amp;</span>quot;<span style="color: #7a0874; font-weight: bold;">&#40;</span>The .pub <span style="color: #c20cb9; font-weight: bold;">file</span> created from <span style="color: #c20cb9; font-weight: bold;">ssh-keygen</span> <span style="color: #660033;">-t</span> rsa<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #000000; font-weight: bold;">&amp;</span>quot;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000; font-weight: bold;">&amp;</span>quot;Example:  $<span style="color: #000000;">0</span> remote_rsa.pub<span style="color: #000000; font-weight: bold;">&amp;</span>quot;
<span style="color: #7a0874; font-weight: bold;">exit</span>
<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-f</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>
<span style="color: #007800;">keyid</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">cut</span> <span style="color: #660033;">-f3-</span> <span style="color: #000000; font-weight: bold;">&amp;</span><span style="color: #666666; font-style: italic;">#39;-d &amp;#39; &amp;lt; $1`</span>
<span style="color: #000000; font-weight: bold;">else</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000; font-weight: bold;">&amp;</span>quot;I can<span style="color: #000000; font-weight: bold;">&amp;</span><span style="color: #666666; font-style: italic;">#39;t find $1 !&amp;quot;</span>
<span style="color: #7a0874; font-weight: bold;">exit</span>
<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000; font-weight: bold;">&amp;</span>quot;Using ID <span style="color: #007800;">$keyid</span><span style="color: #000000; font-weight: bold;">&amp;</span>quot;
<span style="color: #666666; font-style: italic;"># variables to make life easier</span>
<span style="color: #007800;">sshdir</span>=~<span style="color: #000000; font-weight: bold;">/</span>.ssh
<span style="color: #007800;">keyfile</span>=~<span style="color: #000000; font-weight: bold;">/</span>.ssh<span style="color: #000000; font-weight: bold;">/</span>authorized_keys
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-d</span> <span style="color: #000000; font-weight: bold;">&amp;</span>quot;<span style="color: #007800;">$sshdir</span><span style="color: #000000; font-weight: bold;">&amp;</span>quot; <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000; font-weight: bold;">&amp;</span>quot;Making <span style="color: #007800;">$sshdir</span><span style="color: #000000; font-weight: bold;">&amp;</span>quot;
<span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #000000; font-weight: bold;">&amp;</span>quot;<span style="color: #007800;">$sshdir</span><span style="color: #000000; font-weight: bold;">&amp;</span>quot;
<span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">700</span> <span style="color: #000000; font-weight: bold;">&amp;</span>quot;<span style="color: #007800;">$sshdir</span><span style="color: #000000; font-weight: bold;">&amp;</span>quot;
<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">&amp;</span>quot;<span style="color: #007800;">$keyfile</span><span style="color: #000000; font-weight: bold;">&amp;</span>quot; <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000; font-weight: bold;">&amp;</span>quot;Creating <span style="color: #007800;">$keyfile</span><span style="color: #000000; font-weight: bold;">&amp;</span>quot;
<span style="color: #c20cb9; font-weight: bold;">touch</span> <span style="color: #000000; font-weight: bold;">&amp;</span>quot;<span style="color: #007800;">$keyfile</span><span style="color: #000000; font-weight: bold;">&amp;</span>quot;
<span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">644</span> <span style="color: #000000; font-weight: bold;">&amp;</span>quot;<span style="color: #007800;">$keyfile</span><span style="color: #000000; font-weight: bold;">&amp;</span>quot;
<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #000000; font-weight: bold;">&amp;</span>quot;<span style="color: #007800;">$keyid</span><span style="color: #000000; font-weight: bold;">&amp;</span>quot; <span style="color: #000000; font-weight: bold;">&amp;</span>quot;<span style="color: #007800;">$keyfile</span><span style="color: #000000; font-weight: bold;">&amp;</span>quot; <span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null
<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: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000; font-weight: bold;">&amp;</span>quot;Adding key to <span style="color: #007800;">$keyfile</span><span style="color: #000000; font-weight: bold;">&amp;</span>quot;
<span style="color: #c20cb9; font-weight: bold;">cat</span> $<span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt;<span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #000000; font-weight: bold;">&amp;</span>quot;<span style="color: #007800;">$keyfile</span><span style="color: #000000; font-weight: bold;">&amp;</span>quot;
<span style="color: #000000; font-weight: bold;">else</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000; font-weight: bold;">&amp;</span>quot;Key <span style="color: #007800;">$keyid</span> already present.<span style="color: #000000; font-weight: bold;">&amp;</span>quot;
<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #666666; font-style: italic;"># the end</span></pre></div></div>

<p>Or: <a href="http://red-green.com/keyit.sh" title="Script to automatically add a RSA/DSA public key">download the auto SSH script</a> .</p>
<h1>Notes About the Script</h1>
<p>The script doesn&#39;t do anything fancy, and once it has been run, adding additional keys is as simple as doing cat id_rsa.pub &gt;&gt; ./ssh/authorized_keys ! But, if the system hasn&#39;t been rsa public keyed before, this script will take care of setting all the file permissions correctly.</p>
<h1>Configuring SSH to use the RSA Key</h1>
<p>In your ~/.ssh/config file, add the following lines: <code>Host nameyoucallsite Hostname 10.0.0.1 (or hostname) IdentityFile ~/.ssh/id_rsa User usernameonsite</code> The hostname, if you set it with an IP address, it will always work (assuming your internet connection is working). If you use a hostname, it will only work if DNS is working. (Hint, if the server you are sshing into is the DNS server for that domain, make sure you have the IP address somewhere just in case!) User is the login name for that box. The IdentityFile is the file that you created, I usually create many keys, one for each project that I am involved in. Once configured, doing `ssh nameyoucallsite` is all that is required to login to the site.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.red-green.com/2007/06/automatic-ssh-login-using-rsadsa-keys/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
