<?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>Fernandez de Quilon &#187; BASh</title>
	<atom:link href="http://www.jefferyfernandez.id.au/category/bash/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jefferyfernandez.id.au</link>
	<description>between flat screens and grey matter</description>
	<lastBuildDate>Sat, 28 Aug 2010 04:28:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1-alpha</generator>
		<item>
		<title>Automate SSH logins with RSA/DSA keys</title>
		<link>http://www.jefferyfernandez.id.au/2007/12/10/automate-ssh-logins-with-rsadsa-keys/</link>
		<comments>http://www.jefferyfernandez.id.au/2007/12/10/automate-ssh-logins-with-rsadsa-keys/#comments</comments>
		<pubDate>Mon, 10 Dec 2007 05:22:33 +0000</pubDate>
		<dc:creator>Jeffery</dc:creator>
				<category><![CDATA[BASh]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.jefferyfernandez.id.au/2007/12/10/automate-ssh-logins-with-rsadsa-keys/</guid>
		<description><![CDATA[Often when you are administrating remote Linux servers, you tend to login to the servers via your favorite shell. And every time when you login you are prompted for a user name + password to authenticate your session. This gets &#8230; <a href="http://www.jefferyfernandez.id.au/2007/12/10/automate-ssh-logins-with-rsadsa-keys/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.jefferyfernandez.id.au/wp-content/uploads/2007/12/utilities-terminal.png" alt="Automated Shell Login" align="left" />Often when you are administrating remote Linux servers, you tend to login to the servers via your favorite shell. And every time when you login you are prompted for a user name + password to authenticate your session. This gets a bit tedious if you have many passwords to remember for different logins. This is were <a href="http://www.google.com.au/search?q=ssh+keys&amp;ie=utf-8&amp;oe=utf-8&amp;aq=t&amp;rls=org.mozilla:en-US:official&amp;client=firefox-a" title="Search Google for SSH keys" target="_blank">ssh keys</a> can be used to save you from typing your credentials for every ssh login you execute. Once you have setup your SSH key, you are just one step away from making your life a whole lot easier.</p>
<p>I have put together a shell script which saves me the trouble of remembering various combinations of user names + passwords. It looks something like this: <code class="usercommand">cat ~/.ssh/id_dsa.pub | ssh jeffery@example.com "(mkdir .ssh&amp;&gt;/dev/null; chmod 700 .ssh &amp;&amp; cat - &gt;&gt; .ssh/authorized_keys ) &amp;&amp; chmod 600 .ssh/authorized_keys"</code><span id="more-39"></span><br />
<script type="text/javascript"><!--
google_ad_client = "pub-5896900602713932";
google_ad_width = 468;
google_ad_height = 60;
google_ad_format = "468x60_as";
google_ad_type = "text_image";
//2007-10-07: general
google_ad_channel = "5562041263";
//-->
</script><br />
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<h3>Cat Piped Over Ssh explained</h3>
<p>Lets take it step by step and go through what the above command actually does. This is the order of what happens when the above command is executed:</p>
<ol>
<li>Concatenate the contents (<strong><em>cat ~/.ssh/id_dsa.pub </em></strong>) of my DSA public key</li>
<li>Pipe the contents (<strong><em> | </em></strong>) to the ssh command <strong><em>ssh jeffery@example.com</em></strong></li>
<li>I am then executing four commands to the remote host via SSH
<ol>
<li>The first command <strong><em>mkdir .ssh&amp;&gt;/dev/null</em></strong> is making sure the remote folder .ssh exists by creating it. And if the directory already exists, it will give an error message, but that error message is discarded to <a href="http://en.wikipedia.org/wiki/Data_sink" target="_blank" title="Data Sink">/dev/null</a>. There could be a situation when this folder may not exist on the remote machine, hence we are making sure it exists.</li>
<li>Next we make sure the .ssh folder is writable with the command <strong><em>chmod 700 .ssh</em></strong>.</li>
<li>The double-ampersand (<strong><em>&amp;&amp;</em></strong>) which follows these two commands has a special meaning. It states if the previous command executed is not successful, do not execute any more commands in that statement. The only time this would fail would be if there is a folder called .ssh and it is not owned/writable by the user who is supposed to own it. In my case that would be the user &#8220;jeffery&#8221;.</li>
<li>The next command we see is <strong><em>cat &#8211; &gt;&gt; .ssh/authorized_keys</em></strong>. If you remember in Step 1, the cat command which piped the contents of my DSA public key has now produced a Standard Input. This cat command is now taking that input and appending it to the  .ssh/authorized_keys file. If the file didn&#8217;t exist, it should automatically have created that file and appended my DSA public key into it.</li>
<li>Finally we make sure that the authorized_keys file in secure from other users by changing the permissions <strong><em>chmod 600 .ssh/authorized_keys</em></strong>.</li>
</ol>
</li>
<li>After this command is executed, the shell would prompt you to enter the accounts password.
<ol>
<li>If this is the first time you are accessing the remote host, you will be prompted to verify the &#8220;authenticity&#8221; of the host. Type &#8220;yes&#8221; and hit Enter key.</li>
<li>Provide the login password to complete the setup for Automated Login.</li>
</ol>
</li>
</ol>
<h3>Shell Script</h3>
<p>Finally to make things a bit more easier, here is the shell script which you can use by providing the user@domain as the parameter  to setup your Automated logins.<br />
<code class="textinput">#!/bin/bash<br />
user_domain=$1<br />
echo "Automating Login for $user_domain"<br />
# Auto SSH<br />
cat ~/.ssh/id_dsa.pub | ssh $user_domain "(mkdir .ssh&amp;&gt;/dev/null; chmod 700 .ssh &amp;&amp; cat - &gt;&gt; .ssh/authorized_keys ) &amp;&amp; chmod 600 .ssh/authorized_keys"<br />
</code><br />
Copy the Above into a file called auto_ssh.sh, make it executable and run it. Change the user name and remote host to reflect your details. <code class="usercommand">./auto_ssh.sh jeffery@example.com</code></p>
<h3>Resources</h3>
<ul>
<li><a href="http://www-128.ibm.com/developerworks/library/l-keyc.html" title="OpenSSH key management" target="_blank">http://www-128.ibm.com/developerworks/library/l-keyc.html</a></li>
<li><a href="http://www.red-green.com/2007/06/automatic-ssh-login-using-rsadsa-keys/" target="_blank">http://www.red-green.com/2007/06/automatic-ssh-login-using-rsadsa-keys/</a></li>
</ul>
<div style="float:left;margin:0px 0px 0px 0px;"></div>]]></content:encoded>
			<wfw:commentRss>http://www.jefferyfernandez.id.au/2007/12/10/automate-ssh-logins-with-rsadsa-keys/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Shell&#8217;s History</title>
		<link>http://www.jefferyfernandez.id.au/2005/10/01/the-shells-history/</link>
		<comments>http://www.jefferyfernandez.id.au/2005/10/01/the-shells-history/#comments</comments>
		<pubDate>Sat, 01 Oct 2005 02:49:17 +0000</pubDate>
		<dc:creator>Jeffery</dc:creator>
				<category><![CDATA[BASh]]></category>

		<guid isPermaLink="false">http://kangaroo.jeffery/?p=3</guid>
		<description><![CDATA[The Shell&#8217;s History The shell remembers the history of your last typed commands. It is what you see when you use the up and down keys in Bash. There are plenty of ways to use this history! I will write &#8230; <a href="http://www.jefferyfernandez.id.au/2005/10/01/the-shells-history/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<h3>The Shell&#8217;s History</h3>
<p>
The shell remembers the history of your last typed commands. It is what you see when you use the up and down keys in Bash.
</p>
<p>
There are plenty of ways to use this history! I will write some tips here that I know but don&#8217;t hesitate to add more in comments.
</p>
<ul>
<li>the ! tip: starting a line by ! followed by the first few letters of a previous command recalls it, very useful !</li>
<li>! followed by a number recalls this command.</li>
<li>the !? tip: is somewhat similar but doesn&#8217;t only look at command <i>starting</i> with the following letters but <i>containing</i> them !</li>
<li>&#8216;#&#8217; comments the commands but still records it. (if you have something to check while typing a long command)</li>
<li>of course the <strong class="strong">history</strong> command shows you the last commands <img src='http://www.jefferyfernandez.id.au/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </li>
<li>[ctrl-r] put you in history mode</li>
<li>if you don&#8217;t like this feature, you can filter it with <strong class="strong">HISTIGNORE</strong></li>
</ul>
<p>
example : </p>
<pre class="usercommand">export HISTIGNORE=&quot;&amp;:ls:\[bf\]g:exit&quot;</pre>
<p>suppresses duplicate commands, the simple invocation of &#8216;ls&#8217; without any arguments, and the shell built-ins bg, fg, and exit:
</p>
<p>
And if you include the expression &#8220;[ t]*&#8221; in the HISTIGNORE string, you can suppress history recording at will for any given command just by starting with a space!</p>
<div style="float:left;margin:0px 0px 0px 0px;"></div>]]></content:encoded>
			<wfw:commentRss>http://www.jefferyfernandez.id.au/2005/10/01/the-shells-history/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
