<?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>HEAVYWORKS &#187; System Administration</title>
	<atom:link href="http://www.heavyworks.net/blog/category/system-administration/feed" rel="self" type="application/rss+xml" />
	<link>http://www.heavyworks.net</link>
	<description>Extreme Software Engineering</description>
	<lastBuildDate>Wed, 28 Jul 2010 20:39:17 +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>Don&#8217;t be ruthless to your processes</title>
		<link>http://www.heavyworks.net/blog/posts/dont-be-ruthless-to-your-processes</link>
		<comments>http://www.heavyworks.net/blog/posts/dont-be-ruthless-to-your-processes#comments</comments>
		<pubDate>Wed, 28 Jul 2010 20:38:35 +0000</pubDate>
		<dc:creator>Jan Seidl</dc:creator>
				<category><![CDATA[System Administration]]></category>
		<category><![CDATA[bsd]]></category>
		<category><![CDATA[kill]]></category>
		<category><![CDATA[process]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[signal]]></category>
		<category><![CDATA[terminal]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://www.heavyworks.net/?p=544</guid>
		<description><![CDATA[It&#8217;s a common (while wrong) practice while administering *NIX/BSD servers (or even stations) to terminate hanged processes with the kill command. Although the name suggests that it will mercilessly murder the process, its more a signal thrower. Signals tell processes to take determinate actions such as pause, continue, terminate, interrupt current work etc. Anatomy of [...]


Related posts:<ol><li><a href='http://www.heavyworks.net/blog/posts/automating-human-intervention-tasks-with-expect' rel='bookmark' title='Permanent Link: Automating human intervention tasks with Expect'>Automating human intervention tasks with Expect</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s a common (while wrong) practice while administering *NIX/BSD servers (or even stations) to terminate hanged processes with the <code>kill</code> command.</p>
<p>Although the name suggests that it will mercilessly murder the process, its more a <em>signal thrower</em>. Signals tell processes to take determinate actions such as pause, continue, terminate, interrupt current work etc.<br />
<span id="more-544"></span></p>
<h2>Anatomy of process&#8217; death process</h2>
<p>There are basically four forms to terminate a process:</p>
<div id="attachment_547" class="wp-caption aligncenter" style="width: 434px"><img src="http://www.heavyworks.net/wordpress/wp-content/uploads/killComputer.gif" alt="" title="Killing the PC" width="424" height="341" class="size-full wp-image-547" /><p class="wp-caption-text">Wrong way to terminate a process</p></div>
<h3>Signal 15, SIGTERM. The Terminate Call</h3>
<p>Tells your process to end the task cleanly, closing all network connections, file handles, notifying child processes, resetting the terminal and go home in peace. The first thing to do when it becomes unresponsive.</p>
<h3>Signal 2, SIGINT. The Interrupt &#8211; A slap on the face</h2>
<p>Tells your process to stop what it is doing right now and leave immediately. The only way when SIGTERM fails to do the job cleanly. <kbd>CTRL+C</kbd> will throw this signal too.</p>
<h3>Signal 1, SIGHUP. The Hangup &#8211; Kick on the tummy</h3>
<p>Quite similar to SIGINT, SIGHUP is one step up. The Hangup is equivalent to the physical medium holding the process going down. It was very common on dial-up lines to indicate that the line had hang-up the call thus terminating the connection.</p>
<h3>Signal 9, SIGKILL. The Kill &#8211; A bullet on process&#8217; head</h3>
<p>SIGKILL will wipe the process out from your tree leaving all the crap it was using. Its the worst way of terminating a process since it will keep your resources open and can lead to any sort of mayhem.</p>
<h2>So what to do?</h2>
<p>As mentioned on <a href="http://partmaps.org/era/unix/award.html#uuk9letter">UUK9 (Useless use of Kill -9)</a>:</p>
<blockquote><p>Generally, send 15 <em>(SIGTERM)</em>, and wait a second or two, and if that doesn&#8217;t<br />
work, send 2 <em>(SIGINT)</em>, and if that doesn&#8217;t work, send 1 <em>(SIGHUP)</em>.  If that doesn&#8217;t,<br />
REMOVE THE BINARY because the program is badly behaved!</p></blockquote>
<p>Quite extremist, but totally true!</p>
<p>Treat your processes with dignity, and they won&#8217;t betray you! HTH!</p>

<p>Related posts:<ol><li><a href='http://www.heavyworks.net/blog/posts/automating-human-intervention-tasks-with-expect' rel='bookmark' title='Permanent Link: Automating human intervention tasks with Expect'>Automating human intervention tasks with Expect</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.heavyworks.net/blog/posts/dont-be-ruthless-to-your-processes/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Automating human intervention tasks with Expect</title>
		<link>http://www.heavyworks.net/blog/posts/automating-human-intervention-tasks-with-expect</link>
		<comments>http://www.heavyworks.net/blog/posts/automating-human-intervention-tasks-with-expect#comments</comments>
		<pubDate>Thu, 22 Apr 2010 17:23:20 +0000</pubDate>
		<dc:creator>Jan Seidl</dc:creator>
				<category><![CDATA[System Administration]]></category>
		<category><![CDATA[automation]]></category>
		<category><![CDATA[expect]]></category>
		<category><![CDATA[tcl]]></category>
		<category><![CDATA[tk]]></category>

		<guid isPermaLink="false">http://www.heavyworks.net/?p=495</guid>
		<description><![CDATA[I administrate several servers and SSH password management were a big issue until I changed all my servers logins to use private keys. Things got really nicer when I discovered SSH aliases. Some of my clients are hosted on shared hostings and some of them doesn&#8217;t allow password-less authentication &#8220;in behalf of my security&#8221;. Well, [...]


Related posts:<ol><li><a href='http://www.heavyworks.net/blog/posts/typing-less-with-ssh' rel='bookmark' title='Permanent Link: Typing less with SSH'>Typing less with SSH</a></li>
<li><a href='http://www.heavyworks.net/blog/posts/smartly-resolving-your-wordpress-pages-and-posts-javascript-and-css-dependences' rel='bookmark' title='Permanent Link: Smartly resolving your WordPress pages and posts JavaScript and CSS dependences'>Smartly resolving your WordPress pages and posts JavaScript and CSS dependences</a></li>
<li><a href='http://www.heavyworks.net/blog/posts/scytale-a-greek-cryptography-implemented-in-c' rel='bookmark' title='Permanent Link: Scytale, a greek cryptography system implemented in C++'>Scytale, a greek cryptography system implemented in C++</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>I administrate several servers and <acronym title="Secure Shell">SSH</acronym> password management were a big issue until I changed all my servers logins to use private keys. Things got really nicer when I discovered <a href="http://www.heavyworks.net/blog/posts/typing-less-with-ssh" title="Typing less with SSH @ Heavyworks"><acronym title="Secure Shell">SSH</acronym> aliases</a>.</p>
<p>Some of my clients are hosted on shared hostings and some of them doesn&#8217;t allow password-less authentication &#8220;in behalf of my security&#8221;. Well, I can&#8217;t really afford opening my password manager, locating it and then copying and pasting back to my terminal. Too much time spent.</p>
<p>I have heard about expect long ago but never quite stopped to look at it since I never really had that need but in this case it came quite handy. Hop in aboard the new less typing world!<br />
<span id="more-495"></span></p>
<blockquote><p>Expect is a Unix automation and testing tool, written by Don Libes [from <a href="http://www.nist.gov">NIST</a>] as an extension to the Tcl scripting language, for interactive applications such as telnet, ftp, passwd, fsck, rlogin, tip, ssh, and others. It uses Unix pseudo terminals to wrap up subprocesses transparently, allowing the automation of arbitrary applications that are accessed over a terminal. With Tk, interactive applications can be wrapped in X11 GUIs.</p></blockquote>
<p><em>Source: <a href="http://en.wikipedia.org/wiki/Expect">Wikipedia</a></em></p>
<h2>Expect Overview</h2>
<p>Expect runs a very simple kind of script file in its own language. This script contains the logic to perform the automation and it&#8217;s called as first argument to the <code>expect</code> command. For a argument-less script named <code>fake_ssh_host-x.exp</code> the call would be.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">expect fake_ssh_host-x.exp</pre></div></div>

<p>If it took any argument it would just be appended to the call:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">expect fake_ssh_host-x.exp somefile.txt</pre></div></div>

<h2>Quick Expect anatomy</h2>
<p>Expect directives are line-separated and not terminated. Expect even has some object-notation for grouping <code>expect</code> events.</p>
<h3>Variables</h3>
<p>Variables are assigned in expect with the <code>set</code> directive.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">set</span> pass <span style="color: #ff0000;">&quot;mypass&quot;</span></pre></div></div>

<p>Variables are further referenced prefixed with a dollar-sign <code>$</code>.</p>
<h3>Command-line arguments</h3>
<p>Command-line arguments are get through the <code>$argv</code> variable and the <code>lindex</code> call. Now that we have learned how to assign variables, let&#8217;s assign one with a command-line argument.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">set</span> filename <span style="color: #7a0874; font-weight: bold;">&#91;</span>lindex <span style="color: #007800;">$argv</span> <span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#93;</span></pre></div></div>

<p>Note that indexes start at <code>0</code>, as the standard.<br />
You can have multiple command-line arguments:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">set</span> filename <span style="color: #7a0874; font-weight: bold;">&#91;</span>lindex <span style="color: #007800;">$argv</span> <span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">set</span> user <span style="color: #7a0874; font-weight: bold;">&#91;</span>lindex <span style="color: #007800;">$argv</span> <span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">set</span> host <span style="color: #7a0874; font-weight: bold;">&#91;</span>lindex <span style="color: #007800;">$argv</span> <span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#93;</span></pre></div></div>

<h3>Spawning the tampered process</h3>
<p>We use Expect in order to tamper output from a process and thus automate the inputs. We need to tell our Expect script which process it must spawn. This is done though the <code>spawn</code> directive that prefixes a normal command-line statement for that call.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">spawn <span style="color: #c20cb9; font-weight: bold;">ssh</span> user<span style="color: #000000; font-weight: bold;">@</span>host</pre></div></div>

<h3>Timeout</h3>
<p>Timeout determines the number of seconds that the process has to respond before being considered jammed (or b0rked) and is set through the <code>timeout</code> directive, much like as a variable is.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># one minute timeout</span>
<span style="color: #000000; font-weight: bold;">set</span> timeout <span style="color: #000000;">60</span></pre></div></div>

<p><em><code>timeout</code> is disabled if set to <code>-1</code></em></p>
<h3>Observing data</h3>
<p>The <code>expect</code> directive tells the script which text to expect from standard output.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">expect <span style="color: #ff0000;">&quot;String&quot;</span></pre></div></div>

<h3>Posting data</h3>
<p>Posting data to standard input is done through the <code>send</code> directive. This statement when precede by an <code>expect</code> statement will execute only when given string matched.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">send <span style="color: #007800;">$pass</span></pre></div></div>

<h3>Grouping expectations and posts</h3>
<p>This kinda object-notation is used to couple <code>expect</code>/<code>send</code> statements.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">expect <span style="color: #7a0874; font-weight: bold;">&#123;</span>
	<span style="color: #ff0000;">&quot;password:&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
		send <span style="color: #ff0000;">&quot;<span style="color: #007800;">$pass</span><span style="color: #000099; font-weight: bold;">\r</span>&quot;</span>
	<span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span> 
<span style="color: #666666; font-style: italic;"># or shortened</span>
expect <span style="color: #7a0874; font-weight: bold;">&#123;</span>
	<span style="color: #ff0000;">&quot;password:&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span> send <span style="color: #ff0000;">&quot;<span style="color: #007800;">$pass</span><span style="color: #000099; font-weight: bold;">\r</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<p>If you need to append more commands on an <code>expect</code> block just append the line within the expected element closure (in expanded form) or append to the line in a semi-colon delimited form.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">expect <span style="color: #7a0874; font-weight: bold;">&#123;</span>
	<span style="color: #ff0000;">&quot;password:&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
		send <span style="color: #ff0000;">&quot;<span style="color: #007800;">$pass</span><span style="color: #000099; font-weight: bold;">\r</span>&quot;</span>
		<span style="color: #000000; font-weight: bold;">set</span> timeout <span style="color: #660033;">-1</span>
	<span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span> 
<span style="color: #666666; font-style: italic;"># or shortened</span>
expect <span style="color: #7a0874; font-weight: bold;">&#123;</span>
	<span style="color: #ff0000;">&quot;password:&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span> send <span style="color: #ff0000;">&quot;<span style="color: #007800;">$pass</span><span style="color: #000099; font-weight: bold;">\r</span>&quot;</span> ; <span style="color: #000000; font-weight: bold;">set</span> timeout <span style="color: #660033;">-1</span> <span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<p>Coupling multiple expectations is also easy:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">expect <span style="color: #7a0874; font-weight: bold;">&#123;</span>
	<span style="color: #ff0000;">&quot;yes/no):&quot;</span> send <span style="color: #ff0000;">&quot;yes&quot;</span>
	<span style="color: #ff0000;">&quot;password:&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span> send <span style="color: #ff0000;">&quot;<span style="color: #007800;">$pass</span><span style="color: #000099; font-weight: bold;">\r</span>&quot;</span> ; <span style="color: #000000; font-weight: bold;">set</span> timeout <span style="color: #660033;">-1</span> <span style="color: #7a0874; font-weight: bold;">&#125;</span>
	eof <span style="color: #7a0874; font-weight: bold;">exit</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<h3>Printing messages on screen</h3>
<p>If you want to send messages to the standard output rather than the process&#8217; input, you do exactly like the <code>send</code> statement described earlier in this article but the command is <code>send_user</code>.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">send_user <span style="color: #ff0000;">&quot;Connected to host&quot;</span></pre></div></div>

<h3>Outputting to a file</h3>
<p>Sure, you can always pipe the output natively from the shell with the output redirectors <code>&gt;</code> but we can also do that within Expect by setting the <code>file</code> variable coupled with the <code>open</code> directive.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># filename in example is set to expect.out</span>
<span style="color: #666666; font-style: italic;"># 'w' opens file for writing, 'a' to append</span>
<span style="color: #000000; font-weight: bold;">set</span> <span style="color: #c20cb9; font-weight: bold;">file</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>open expect.out <span style="color: #c20cb9; font-weight: bold;">w</span><span style="color: #7a0874; font-weight: bold;">&#93;</span></pre></div></div>

<p>More documentation can be found on <a href="http://expect.nist.gov/">Expect&#8217;s website</a> or in its man page.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">man</span> expect</pre></div></div>

<h2>Faking a private key authentication <acronym title="Also known as">AKA</acronym> Automating a password authentication</h2>
<p>For both examples we will need variables and the <code>expect</code>, <code>send</code> and <code>spawn</code> directives.</p>
<h3><acronym title="Secure Shell">SSH</acronym> Session</h3>
<p>We will expect the message asking us if we want to accept the key and send <code>yes</code> to accept it. Then we will expect for the <code>password:</code> string and send our password stored in a variable.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/usr/bin/expect -f</span>
<span style="color: #000000; font-weight: bold;">set</span> timeout <span style="color: #660033;">-1</span>
spawn <span style="color: #c20cb9; font-weight: bold;">ssh</span> username<span style="color: #000000; font-weight: bold;">@</span>host
<span style="color: #000000; font-weight: bold;">set</span> pass <span style="color: #ff0000;">&quot;mypass&quot;</span>
expect <span style="color: #7a0874; font-weight: bold;">&#123;</span>
        password: <span style="color: #7a0874; font-weight: bold;">&#123;</span> send <span style="color: #ff0000;">&quot;<span style="color: #007800;">$pass</span><span style="color: #000099; font-weight: bold;">\r</span>&quot;</span>  <span style="color: #7a0874; font-weight: bold;">&#125;</span>
	<span style="color: #7a0874; font-weight: bold;">&#125;</span> <span style="color: #ff0000;">&quot;yes/no)?&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
		send <span style="color: #ff0000;">&quot;yes<span style="color: #000099; font-weight: bold;">\r</span>&quot;</span>
		<span style="color: #000000; font-weight: bold;">set</span> timeout <span style="color: #660033;">-1</span>
        <span style="color: #7a0874; font-weight: bold;">&#125;</span> eof <span style="color: #7a0874; font-weight: bold;">&#123;</span>
                <span style="color: #7a0874; font-weight: bold;">exit</span>
        <span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<h3>SCP Session</h3>
<p>We will follow the same logic from the above example but we&#8217;ll add some command-line arguments to catch the filename and path to be transfered.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/usr/bin/expect -f</span>
<span style="color: #000000; font-weight: bold;">set</span> timeout <span style="color: #660033;">-1</span>
<span style="color: #000000; font-weight: bold;">set</span> filename <span style="color: #7a0874; font-weight: bold;">&#91;</span>lindex <span style="color: #007800;">$argv</span> <span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">set</span> dst_path <span style="color: #7a0874; font-weight: bold;">&#91;</span>lindex <span style="color: #007800;">$argv</span> <span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
spawn <span style="color: #c20cb9; font-weight: bold;">scp</span> <span style="color: #007800;">$filename</span> username<span style="color: #000000; font-weight: bold;">@</span>host:<span style="color: #007800;">$dst_path</span>
<span style="color: #000000; font-weight: bold;">set</span> pass <span style="color: #ff0000;">&quot;mypass&quot;</span>
expect <span style="color: #7a0874; font-weight: bold;">&#123;</span>
        password: <span style="color: #7a0874; font-weight: bold;">&#123;</span> send <span style="color: #ff0000;">&quot;<span style="color: #007800;">$pass</span><span style="color: #000099; font-weight: bold;">\r</span>&quot;</span>  <span style="color: #7a0874; font-weight: bold;">&#125;</span>
	<span style="color: #7a0874; font-weight: bold;">&#125;</span> <span style="color: #ff0000;">&quot;yes/no)?&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
		send <span style="color: #ff0000;">&quot;yes<span style="color: #000099; font-weight: bold;">\r</span>&quot;</span>
		<span style="color: #000000; font-weight: bold;">set</span> timeout <span style="color: #660033;">-1</span>
        <span style="color: #7a0874; font-weight: bold;">&#125;</span> eof <span style="color: #7a0874; font-weight: bold;">&#123;</span>
                <span style="color: #7a0874; font-weight: bold;">exit</span>
        <span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<p>And you&#8217;re done. No more typing and unnecessary time spending.</p>

<p>Related posts:<ol><li><a href='http://www.heavyworks.net/blog/posts/typing-less-with-ssh' rel='bookmark' title='Permanent Link: Typing less with SSH'>Typing less with SSH</a></li>
<li><a href='http://www.heavyworks.net/blog/posts/smartly-resolving-your-wordpress-pages-and-posts-javascript-and-css-dependences' rel='bookmark' title='Permanent Link: Smartly resolving your WordPress pages and posts JavaScript and CSS dependences'>Smartly resolving your WordPress pages and posts JavaScript and CSS dependences</a></li>
<li><a href='http://www.heavyworks.net/blog/posts/scytale-a-greek-cryptography-implemented-in-c' rel='bookmark' title='Permanent Link: Scytale, a greek cryptography system implemented in C++'>Scytale, a greek cryptography system implemented in C++</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.heavyworks.net/blog/posts/automating-human-intervention-tasks-with-expect/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Typing less with SSH</title>
		<link>http://www.heavyworks.net/blog/posts/typing-less-with-ssh</link>
		<comments>http://www.heavyworks.net/blog/posts/typing-less-with-ssh#comments</comments>
		<pubDate>Thu, 04 Mar 2010 21:17:41 +0000</pubDate>
		<dc:creator>Jan Seidl</dc:creator>
				<category><![CDATA[System Administration]]></category>
		<category><![CDATA[aliases]]></category>
		<category><![CDATA[scp]]></category>
		<category><![CDATA[ssh]]></category>

		<guid isPermaLink="false">http://www.heavyworks.net/?p=419</guid>
		<description><![CDATA[For me as a user I always had to type long lines to start my sessions. It&#8217;s no rocket science, you know, but for he who types thousands of characters each day, each character save is golden. We usally start our SSH sessions by typing the following command string: ssh user@domain.tld I&#8217;ve tried to shorten [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.heavyworks.net/wordpress/wp-content/uploads/221006_5456.jpg" alt="" title="" width="608" height="252" class="alignnone size-full wp-image-427" /></p>
<p>For me as a Linux<a title="Linux @ Wikipedia" href="http://en.wikipedia.org/wiki/Linux" class="wikipedia" rel="external wikipedia"><sup>w</sup></a> user I always had to type long lines to start my <acronym title="Secure Shell">SSH</acronym><a title="SSH @ Wikipedia" href="http://en.wikipedia.org/wiki/Ssh" class="wikipedia" rel="external wikipedia"><sup>w</sup></a> sessions. It&#8217;s no rocket science, you know, but for he who types thousands of characters each day, each character save is golden.</p>
<p>We usally start our <acronym title="Secure Shell">SSH</acronym> sessions by typing the following command string:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">ssh</span> user<span style="color: #000000; font-weight: bold;">@</span>domain.tld</pre></div></div>

<p>I&#8217;ve tried to shorten this by adding the domain and its <acronym title="Top Level Domain">TLD</acronym><a title="TLD @ Wikipedia" href="http://en.wikipedia.org/wiki/Tld" class="wikipedia" rel="external wikipedia"><sup>w</sup></a> to my <code>hosts</code> file with a shorter alias like</p>
<pre>
hname hostname.tld
</pre>
<p>But obviously that crashed against Apache<a title="Apache @ Wikipedia" href="http://en.wikipedia.org/wiki/Apache" class="wikipedia" rel="external wikipedia"><sup>w</sup></a> Vhost<a title="Vhost @ Wikipedia" href="http://en.wikipedia.org/wiki/Vhost" class="wikipedia" rel="external wikipedia"><sup>w</sup></a> capability, the request never make it to the other end.</p>
<p>I personally have <acronym title="Secure Shell">SSH</acronym> keys on some of my servers to avoid typing passwords, that is good to prevent against MITM<a title="MITM @ Wikipedia" href="http://en.wikipedia.org/wiki/Mitm" class="wikipedia" rel="external wikipedia"><sup>w</sup></a> attacks and keyloggers, but I still have to type the string mentioned lines above.</p>
<p>Then, with 3 lines in a <acronym title="Secure Shell">SSH</acronym>&#8217;s configuration file on my home directory (yes, you don&#8217;t need to alter the server&#8217;s <acronym title="Secure Shell">SSH</acronym> configuration file and yes, you can do that on your shared hosting&#8217;s shell account).<br />
<span id="more-419"></span><br />
It&#8217;s very simple. <acronym title="Secure Shell">SSH</acronym> allows some user-based configuration in your <code>~/.ssh</code> directory (note that <code>~</code> stands for your home directory (usually <code>/home/yourusername</code>) and it also provides Aliases<a title="Aliases @ Wikipedia" href="http://en.wikipedia.org/wiki/Aliases" class="wikipedia" rel="external wikipedia"><sup>w</sup></a> capability.</p>
<p>The aliases can be configured in such a way that you won&#8217;t need to type neither the FQDN<a title="FQDN @ Wikipedia" href="http://en.wikipedia.org/wiki/Fqdn" class="wikipedia" rel="external wikipedia"><sup>w</sup></a> nor even type a single username EVER MORE! </p>
<p>Your old</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">ssh</span> user<span style="color: #000000; font-weight: bold;">@</span>domain.tld</pre></div></div>

<p>will be shortened to</p>

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

<h2>Ok, talk is cheap, show me the code!</h2>
<h3>Creating the need files and directories</h2>
<p>All the magic occurs on the <code>config</code> in your already-mentioned <code>~/.ssh/</code> directory. If you don&#8217;t have one, create it and secure it, as the following:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">mkdir</span> ~<span style="color: #000000; font-weight: bold;">/</span>.ssh<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">700</span> ~<span style="color: #000000; font-weight: bold;">/</span>.ssh<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>

<p>If the file does not exists, create it and secure it propperly, like:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">touch</span> ~<span style="color: #000000; font-weight: bold;">/</span>.ssh<span style="color: #000000; font-weight: bold;">/</span>config
<span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">600</span> ~<span style="color: #000000; font-weight: bold;">/</span>.ssh<span style="color: #000000; font-weight: bold;">/</span>config</pre></div></div>

<h3>Syntax model</h3>
<pre>
Host [alias name]
HostName [host's fqdn]
User [username to log-in as]
</pre>
<p><em>Without the braces, please!</em></p>
<p>For a user called <code>jdoe</code> on <code>mydomain.com</code> being shorted <code>md</code>, the code would be the following:</p>
<pre>
Host md
HostName mydomain.com
User jdoe
</pre>
<p>Save the file and you can start typing less with SSH:</p>

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

<p>And that&#8217;s IT!</p>
<h2>Wow that&#8217;s great! What else this beauty can do?</h2>
<h3>Omnipresence</h3>
<p>Do you have the same username in a large number of machines, like in a local network? So you have to love the <code>*</code> wildcard.</p>
<pre>
Host *
User jdoe
</pre>
<h3>I have many names</h3>
<p>Want to follow a naming pattern but also wants to have shorter ones? Give multiple aliases!</p>
<pre>
Host gdf gandalf
HostName gandalf.mydomain.com
User jdoe
</pre>
<h3>Avoid the front door</h3>
<p>Security through obscurity is always fun! Have your <acronym title="Secure Shell">SSH</acronym> aliases even in hosts with <code>sshd</code> running in a different port.</p>
<pre>
Host md
HostName mydomain.com
User jdoe
Port 11
</pre>
<h3>Be backwards compatible</h3>
<p>Have outdated <acronym title="Secure Shell">SSH</acronym> servers? I hope not! But if you do, you may also define a different protocol in a host-based manner.</p>
<pre>
Host md
HostName mydomain.com
User jdoe
Protocol 1
</pre>
<h3>Handle multiple keys</h3>
<p>You may specify the specific (what?) <acronym title="Secure Shell">SSH</acronym> key file for a host.</p>
<pre>
Host md
HostName mydomain.com
User jdoe
IdentityFile ~/mykey.pub
</pre>
<h2>And it also works on SCP!</h2>
<p>Oh yeah, file transfers are easier now!</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">scp</span> somefile.txt md:<span style="color: #000000; font-weight: bold;">/</span>path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>upload</pre></div></div>

<p>More parameters can be found on <acronym title="Secure Shell">SSH</acronym> manual, page 5.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">man</span> <span style="color: #c20cb9; font-weight: bold;">ssh</span> <span style="color: #000000;">5</span></pre></div></div>

<p>Phew! That&#8217;s all folks! Hope it helps someone as much as helped me! Anyone have any neat <acronym title="Secure Shell">SSH</acronym> trick?</p>

<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://www.heavyworks.net/blog/posts/typing-less-with-ssh/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Quick Tip: Forcing www. to avoid duplicate content</title>
		<link>http://www.heavyworks.net/blog/posts/quick-tip-forcing-www-to-avoid-duplicate-content</link>
		<comments>http://www.heavyworks.net/blog/posts/quick-tip-forcing-www-to-avoid-duplicate-content#comments</comments>
		<pubDate>Mon, 16 Mar 2009 18:56:31 +0000</pubDate>
		<dc:creator>Jan Seidl</dc:creator>
				<category><![CDATA[System Administration]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[mod_rewrite]]></category>
		<category><![CDATA[seo]]></category>

		<guid isPermaLink="false">http://www.heavyworks.net/?p=222</guid>
		<description><![CDATA[Google (and other search engines) treats subdomains as different websites so if you are linked / accessed both via http://www.yourdomain.com and http://yourdomain.com you may get your content classified as duplicate since will be the same on both. To avoid this simply add a rule to a .htaccess file in your root directory: &#60;IfModule mod_rewrite.c&#62; RewriteEngine [...]


Related posts:<ol><li><a href='http://www.heavyworks.net/blog/posts/typing-less-with-ssh' rel='bookmark' title='Permanent Link: Typing less with SSH'>Typing less with SSH</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Google (and other search engines) treats subdomains as different websites so if you are linked / accessed both via http://www.yourdomain.com and http://yourdomain.com you may get your content classified as duplicate since will be the same on both.</p>
<p>To avoid this simply add a rule to a <code>.htaccess</code> file in your root directory:</p>

<div class="wp_syntax"><div class="code"><pre class="apache" style="font-family:monospace;">&lt;<span style="color: #000000; font-weight:bold;">IfModule</span> mod_rewrite.c&gt;
<span style="color: #00007f;">RewriteEngine</span> <span style="color: #0000ff;">On</span>
<span style="color: #00007f;">RewriteCond</span> %{HTTP_HOST} !^www\.yourdomain\.com [NC]
<span style="color: #00007f;">RewriteRule</span> ^(.*)$ http://www.yourdomain.com/$<span style="color: #ff0000;">1</span> [R=<span style="color: #ff0000;">301</span>,L]
&lt;/<span style="color: #000000; font-weight:bold;">IfModule</span>&gt;</pre></div></div>

<p><em>NOTE: You need to have <code>mod_rewrite</code> enabled in your server in order to do this.</em></p>

<p>Related posts:<ol><li><a href='http://www.heavyworks.net/blog/posts/typing-less-with-ssh' rel='bookmark' title='Permanent Link: Typing less with SSH'>Typing less with SSH</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.heavyworks.net/blog/posts/quick-tip-forcing-www-to-avoid-duplicate-content/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Ubuntu is going Windows-way</title>
		<link>http://www.heavyworks.net/blog/posts/ubuntu-is-going-windows-way</link>
		<comments>http://www.heavyworks.net/blog/posts/ubuntu-is-going-windows-way#comments</comments>
		<pubDate>Mon, 09 Mar 2009 19:01:31 +0000</pubDate>
		<dc:creator>Jan Seidl</dc:creator>
				<category><![CDATA[System Administration]]></category>
		<category><![CDATA[gentoo]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://www.heavyworks.net/?p=196</guid>
		<description><![CDATA[Ubuntu is indeed responsible for the huge growth of Linux home-users due its simplicity of out-of-the-box use. As a brief retrospective, the emerging (in past) Linux distributions were always known to their difficulty on setting up the propper drivers and essential software. If you were installing on a laptop, things turned out to be a [...]


Related posts:<ol><li><a href='http://www.heavyworks.net/blog/posts/typing-less-with-ssh' rel='bookmark' title='Permanent Link: Typing less with SSH'>Typing less with SSH</a></li>
<li><a href='http://www.heavyworks.net/blog/posts/sustainability-application-under-software-development' rel='bookmark' title='Permanent Link: Sustainability application under Software Development'>Sustainability application under Software Development</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Ubuntu is indeed responsible for the huge growth of Linux home-users due its simplicity of out-of-the-box use. As a brief retrospective, the emerging (in past) Linux distributions were always known to their difficulty on setting up the propper drivers and essential software. If you were installing on a laptop, things turned out to be a nightmare. At this point, only IT people used Linux because home-users were scared away (I think it coincided with the ugly GTK 1.x interfaces &#8211; under Gnome).</p>
<p>Ubuntu emerged to aid home-users and be more user-friendly, having and startup installation that would recognize and install all your drivers and give you a starting setup of the most common used tools like e-mail clients, <acronym title="Instant Message">IM</acronym> clients, web browser and an office suite.<br />
<span id="more-196"></span><br />
Things started well, I myself preferred installing an Ubuntu distribution rather than spending hours (or weeks) configuring a Gentoo workstation as I&#8217;m a developer and need a working station to start developing quickly.</p>
<p>The first releases worked well, the weight of the loaded modules was rather unnoticeable and the <acronym title="Operating System">OS</acronym> was running lean  but as time passed Ubuntu went further down in those facilitations and the module-shard grew exponentially. </p>
<p>One of the biggest complains about Windows among power-users is that you have to spend good time removing unwanted software and you keep lots of unwanted drivers in the suburbs of your <acronym title="Operating System">OS</acronym> and Ubuntu is going each day further this approach.</p>
<p><strong>The result</strong><br />
Ubuntu has become each day heavier and it&#8217;s starting to lose stability. Some friends are switching back to their Debian 5 installs or falling back to other distributions. Others predicted that (or are masochists) and never left out their Gentoo installs.</p>
<p><strong>Pros &#038; Cons of the Windows-like behavior</strong><br />
<em>PROS</em><br />
It&#8217;s indeed a good thing to having an <acronym title="Operating System">OS</acronym> working out-of-the-box and for home-users it&#8217;s a must-have solution. This behavior is good as it introduced Linux to a whole new set of users and it still worthy if this user is going to use the installation to home use or office use. The easy operation makes intuitive use of the tools, the menus are well-placed and update routine is just piece of cake.</p>
<p><em>CONS</em><br />
Weight has considerably risen since new versions of the distribution (and bundled software) came out thus making the environment unstable and a little untrustworthy for heavy users (like developers and sysadmins). As most power users kept their old installs and did not adhere to Ubuntu, the support forums are maintained mostly by regular/home users and the solutions are either noneffective or poorly explained. The contrast of this last item is well seen in comparison with Gentoo Wiki Documentation. The Ubuntu Lauchpad (a Bugzilla-like) is a good way to find little more trustworthy information.</p>
<p><strong>Conclusion</strong><br />
Ubuntu shouldn&#8217;t be crucified or left away. It serves well the purpose which it was built for of serving home-users but it&#8217;s each day leaving power users (the ones that adhered) behind even those who used to tune up Ubuntu for performance gain. I think that an online on-demand driver recognition, download and install would be less costly (but it would demand that basic hardware was already properly detected and installed) or an after-install cleanup would just reduce the damages.</p>

<p>Related posts:<ol><li><a href='http://www.heavyworks.net/blog/posts/typing-less-with-ssh' rel='bookmark' title='Permanent Link: Typing less with SSH'>Typing less with SSH</a></li>
<li><a href='http://www.heavyworks.net/blog/posts/sustainability-application-under-software-development' rel='bookmark' title='Permanent Link: Sustainability application under Software Development'>Sustainability application under Software Development</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.heavyworks.net/blog/posts/ubuntu-is-going-windows-way/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Quick Tip: Right terminal emulation over PuTTY</title>
		<link>http://www.heavyworks.net/blog/posts/quick-tip-right-terminal-emulation-over-putty</link>
		<comments>http://www.heavyworks.net/blog/posts/quick-tip-right-terminal-emulation-over-putty#comments</comments>
		<pubDate>Fri, 12 Dec 2008 11:37:21 +0000</pubDate>
		<dc:creator>Jan Seidl</dc:creator>
				<category><![CDATA[System Administration]]></category>
		<category><![CDATA[encoding]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[putty]]></category>
		<category><![CDATA[remote login]]></category>
		<category><![CDATA[ssh]]></category>

		<guid isPermaLink="false">http://www.heavyworks.net/?p=11</guid>
		<description><![CDATA[Have you ever had problems with backspace and stuff over putty? Where's how to solve-it!


Related posts:<ol><li><a href='http://www.heavyworks.net/blog/posts/brazillian-portuguese-pt_br-language-file-for-wp-filebase-released' rel='bookmark' title='Permanent Link: Brazillian Portuguese (pt_BR) language file for WP-Filebase released'>Brazillian Portuguese (pt_BR) language file for WP-Filebase released</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>For every *nix/BSD user, there was no life before <acronym title="Secure Shell">SSH</acronym> and even the crappy Windows plataform got a client (thank god).</p>
<p>But I&#8217;ve personally ran into many bad experiences that <a href="http://www.google.com" title="Google" alt="Google">Google</a> helped me solve.</p>
<p>So, here are my advices for logging into <acronym title="Secure Shell">SSH</acronym> to a linux machine:</p>
<ol>
<li><strong>Change your Terminal Emulation to &#8220;linux&#8221;:</strong> Connection-> Data -> Terminal-Type String = linux</li>
<li><strong>Change your escape sequence to &#8220;Linux&#8221;:</strong> Terminal -> Keyboad -> &#8220;The Function Keys and Keypad&#8221; -> Linux</li>
<li><strong>Set the terminal to UTF-8:</strong> Window -> Translation -> &#8220;Character set translation on received data&#8221; -> UTF-8</li>
</ol>
<p>That&#8217;s it, if someone has other tips envolving PuTTY <acronym title="Secure Shell">SSH</acronym> Client, please share at the comments!</p>

<p>Related posts:<ol><li><a href='http://www.heavyworks.net/blog/posts/brazillian-portuguese-pt_br-language-file-for-wp-filebase-released' rel='bookmark' title='Permanent Link: Brazillian Portuguese (pt_BR) language file for WP-Filebase released'>Brazillian Portuguese (pt_BR) language file for WP-Filebase released</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.heavyworks.net/blog/posts/quick-tip-right-terminal-emulation-over-putty/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
