<?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:creativeCommons="http://backend.userland.com/creativeCommonsRssModule"
>

<channel>
	<title>nointrigue.com &#187; ssh</title>
	<atom:link href="http://www.nointrigue.com/blog/tag/ssh/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.nointrigue.com/blog</link>
	<description>Enoch Lau's Blog</description>
	<pubDate>Wed, 07 Jan 2009 19:14:46 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-nd/2.5/au/</creativeCommons:license>
		<item>
		<title>Bash complete, and other colourful fun</title>
		<link>http://www.nointrigue.com/blog/2008/08/27/bash-complete-and-other-colourful-fun/</link>
		<comments>http://www.nointrigue.com/blog/2008/08/27/bash-complete-and-other-colourful-fun/#comments</comments>
		<pubDate>Wed, 27 Aug 2008 00:59:17 +0000</pubDate>
		<dc:creator>Enoch Lau</dc:creator>
		
		<category><![CDATA[Computing]]></category>

		<category><![CDATA[Meta]]></category>

		<category><![CDATA[The Sydney Grind]]></category>

		<category><![CDATA[bash]]></category>

		<category><![CDATA[bluehost]]></category>

		<category><![CDATA[ssh]]></category>

		<category><![CDATA[subversion]]></category>

		<category><![CDATA[suits]]></category>

		<guid isPermaLink="false">http://www.nointrigue.com/blog/?p=235</guid>
		<description><![CDATA[One of the attractions of Bluehost, my host, is the ability to ssh into your box, which makes administering your site that much easier if you know how to use the *nix command line. (See related post.)
I&#8217;ll just write about two things that I&#8217;ve worked out recently.
Lesson #1: Read the README file.
Well duh, you say. [...]]]></description>
			<content:encoded><![CDATA[<p>One of the attractions of <a href="http://www.bluehost.com/">Bluehost</a>, my host, is the ability to ssh into your box, which makes administering your site that much easier if you know how to use the *nix command line. (<a href="http://www.nointrigue.com/blog/2007/08/11/installing-software-and-other-things-casual-webmasters-should-know/">See related post.</a>)</p>
<p>I&#8217;ll just write about two things that I&#8217;ve worked out recently.</p>
<p><em>Lesson #1: Read the README file.</em></p>
<p>Well duh, you say. The story is, I&#8217;ve had the bash_completion script for some time (a really useful extension that makes typing on the command line that much easier), but I&#8217;ve never quite worked out why it didn&#8217;t work. Now I know why. It&#8217;s because I naively assumed that the <code>bash_completion.sh</code> script was the meat of it, and simply called it from <code>.bashrc</code>, expecting it to just work. It would, ordinarily, but I don&#8217;t have it installed in <code>/etc </code>which is where it expects to be (it&#8217;s in my home directory). If you have somewhere else like me, you will need to set the <code>$BASH_COMPLETION</code> variable and modify the <code>bash_completion.sh</code> script to reflect where you&#8217;ve actually put it.</p>
<p><em>Lesson #2: If you didn&#8217;t set up the system yourself, things might not be as you expect them to be.</em></p>
<p><a href="http://www.suits.it.usyd.edu.au/">SUITS</a> has a bunch of useful scripts that you can use to improve your command line experience on the undergraduate IT servers, and I copied them over to my account on nointrigue.com because I like them so much. One of these scripts sets nice colours for the command line. It was all working fine until I realised <a href="http://tortoisesvn.tigris.org/">TortoiseSVN</a> could no longer access the Subversion repositories via svn+ssh, failing with the error &#8220;connection closed unexpectedly&#8221;. I figured something I added recently was injecting garbage into the stream. It turns out it was the colour-adding script! But why? It was protected like this:</p>

<div class="wp_syntax"><div class="code"><pre class="bash bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;$PS1&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
        . ~<span style="color: #000000; font-weight: bold;">/</span>.bash<span style="color: #000000; font-weight: bold;">/</span>colors
<span style="color: #000000; font-weight: bold;">fi</span></pre></div></div>

<p>That means that it should only have been run if it was running in an &#8220;interactive&#8221; terminal, and the colour-adding script should not have been called if I was using svn+ssh. After some more poking around, I found this in <code>/etc/bashrc</code> (which was being called from <code>.bashrc</code>):</p>

<div class="wp_syntax"><div class="code"><pre class="bash bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># For some unknown reason bash refuses to inherit</span>
<span style="color: #666666; font-style: italic;"># PS1 in some circumstances that I can't figure out.</span>
<span style="color: #666666; font-style: italic;"># Putting PS1 here ensures that it gets loaded every time.</span></pre></div></div>

<p>Uhh, ok, nice work, Bluehost. I guess not many of their customers actually use ssh. At least there was a comment.</p>
<p>But even if it was called, why the colour-adding script was failing in the first place? It turns out that <code>tput colors</code> fails if <code>$TERM</code> is not set, which happens to be so when using svn+ssh. (Actually, this would not normally prevent me from accessing my Subversion repositories. The command line svn seems to ignore errors; however, TortoiseSVN dies the moment it sees anything untoward.) My ultimate solution was to simply pipe error to <code>/dev/null</code>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nointrigue.com/blog/2008/08/27/bash-complete-and-other-colourful-fun/feed/</wfw:commentRss>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-nd/2.5/au/</creativeCommons:license>
	</item>
		<item>
		<title>Installing software, and other things casual webmasters should know</title>
		<link>http://www.nointrigue.com/blog/2007/08/11/installing-software-and-other-things-casual-webmasters-should-know/</link>
		<comments>http://www.nointrigue.com/blog/2007/08/11/installing-software-and-other-things-casual-webmasters-should-know/#comments</comments>
		<pubDate>Sat, 11 Aug 2007 13:52:54 +0000</pubDate>
		<dc:creator>Enoch Lau</dc:creator>
		
		<category><![CDATA[Computing]]></category>

		<category><![CDATA[bash]]></category>

		<category><![CDATA[bluehost]]></category>

		<category><![CDATA[cpanel]]></category>

		<category><![CDATA[cygwin]]></category>

		<category><![CDATA[hosting]]></category>

		<category><![CDATA[latex]]></category>

		<category><![CDATA[linux]]></category>

		<category><![CDATA[privoxy]]></category>

		<category><![CDATA[putty]]></category>

		<category><![CDATA[ssh]]></category>

		<category><![CDATA[subversion]]></category>

		<category><![CDATA[vim]]></category>

		<guid isPermaLink="false">http://www.nointrigue.com/blog/2007/08/11/installing-software-and-other-things-casual-webmasters-should-know/</guid>
		<description><![CDATA[In this tutorial, I&#8217;m going to write about a number of things that will be useful to you if you have your own website hosting. This article is geared for beginners, and requires no prerequisites apart from some common sense! Now, I host nointrigue.com on a shared Linux server with Bluehost, which means that my [...]]]></description>
			<content:encoded><![CDATA[<p>In this tutorial, I&#8217;m going to write about a number of things that will be useful to you if you have your own website hosting. This article is geared for beginners, and requires no prerequisites apart from some common sense! Now, I host nointrigue.com on a shared Linux server with <a href="http://www.bluehost.com/">Bluehost</a>, which means that my website shares a physical computer with a number of other users. This setup is fairly common, so I&#8217;ll be writing with an assumption that this is the kind of arrangement that you have. I&#8217;ll cover some basic, but useful, shell commands to make your life easier, and explain how to install additional software on your host.</p>
<p><span id="more-91"></span></p>
<p><strong>Getting started</strong></p>
<p>Typically, you will have FTP access to your shared host, but not all shared hosts allow shell access to your server. To follow this tutorial, you will need to have shell (SSH) access to your host (which, by the way, I am assuming is a Linux box, which is the usual case). Even if your hosting package has this feature, you may have to file a support request to enable it, as is the case with Bluehost (see the SSH link in cPanel). (Actually, I lie. You can still do the installing software part, but it may prove far more difficult - see below for details.)</p>
<p>To connect to your server, you will need an SSH client on your computer. If you are using Mac OS X or some version of Linux, you will probably have OpenSSH installed already. If you are using Windows, you can either install <a href="http://www.cygwin.com/">Cygwin</a> (make sure you select the OpenSSH package) or use <a href="http://www.chiark.greenend.org.uk/~sgtatham/putty/">PuTTY</a>. If you don&#8217;t have a need for a Unix-like environment on your Windows machine, and you just want SSH, the latter is probably a simpler choice.</p>
<ul>
<li>If you are using OpenSSH, open up a command prompt or terminal, and type <code>ssh <em>username</em>@<em>yourdomain.com</em></code> filling in the username and your domain name as required.</li>
<li>If you are using PuTTY, run <code>putty.exe</code>, enter your host name and press Open.</li>
</ul>
<p>For both, if you are prompted about storing the server&#8217;s fingerprint, just type or click yes.</p>
<p><a href='http://www.nointrigue.com/blog/wp-content/uploads/2007/08/putty-main.png' title='putty-main.png'><img src='http://www.nointrigue.com/blog/wp-content/uploads/2007/08/putty-main.thumbnail.png' alt='putty-main.png' /></a></p>
<p>You should now be presented with a shell prompt, where you can type in commands (which you issue by pressing Enter after typing them in). It may seem like a regression back to the 1980s days of MS-DOS, but it&#8217;s quite a convenient way of controlling a server that&#8217;s far away from you.</p>
<p>To avoid having to enter your password every time, you can <a href="http://mah.everybody.org/docs/ssh">use an SSH agent</a>.</p>
<p><a href='http://www.nointrigue.com/blog/wp-content/uploads/2007/08/putty-loggedin.png' title='putty-loggedin.png'><img src='http://www.nointrigue.com/blog/wp-content/uploads/2007/08/putty-loggedin.thumbnail.png' alt='putty-loggedin.png' /></a></p>
<p><strong>Getting to know your shell commands</strong></p>
<p>This is not intended to be an exhaustive list of commands that you can type; instead, my aim is to write down a number of commands that inexperienced users can just quote verbatim to do what they need to do. Parts in italics are to be replaced as appropriate.</p>
<ul>
<li><code>cd <em>directory</em></code>: this is how you enter into a directory. Commands are always executed relative to the current directory. ~ is your home directory. Just type <code>cd</code> to return to your home directory.</li>
<li><code>ls</code>: display the contents of the current directory. Type <code>la -la</code> to make it display hidden files and detailed information about your files.</li>
<li><code>mkdir <em>directory</em></code>: create a directory.</li>
<li><code>rmdir <em>directory</em></code>: remove a directory. The directory must be empty.</li>
<li><code>rm <em>file</em></code>: delete a file. Use <code>rm *</code> to delete all files in the current directory, or use <code>rm -rf *</code> to delete all files <em>and subdirectories</em> in the current directory (use with caution!).</li>
<li><code>cp <em>oldname newname</em></code>: copy a file.</li>
<li><code>mv <em>oldname newname</em></code>: move a file. This command is also used to rename files, since the act of renaming is just the same as moving. You can move a file up a directory by using <code>mv <em>file</em> ..</code>, and a file into a subdirectory using <code>mv <em>file subdirectory</em></code>.</li>
<li><code>pwd</code>: display the full path to the current directory.</li>
<li><code>less <em>file</em></code>: view a file. Use the arrow keys or page up and page down to move around the document. Press q to exit.</li>
<li><code>find -name <em>wildcard</em></code>: use this to search the current directory and its subdirectories for a file with a name that matches the wildcard expression.</li>
<li><code>ln -s <em>linkname filename</em></code>: a symbolic link is like a shortcut that allows a file to appear in two different places - but both the existing name and the new link name refer to the same file.</li>
</ul>
<p>To find out more about these commands, type <code>man <em>command</em></code>, and press q to exit. If something screws up, pressing Ctrl+C should kill whatever command you&#8217;ve just issued.</p>
<p><strong>Editing on the go</strong></p>
<p>Another activity that I use SSH for quite a bit is editing configuration files directory on the server. That saves me having to download the file to my computer, making the changes, and then uploading it back up again. A good text-based editor is <code>vim</code>, and here are just a few commands to get you started.</p>
<ul>
<li>To start vim with a file open, use <code>vim <em>file</em></code>.</li>
<li>To move around, the arrow keys, home, end, page down and page up work as expected.</li>
<li>To go into editing mode, press <code>i</code>, and then any keys that you press will be added to the document itself. To get out of this mode, press Esc.</li>
<li>When you&#8217;re not in editing mode, you can issue commands to the editor. For example: <code>:q</code> to exit, <code>:q!</code> to exit without saving changes, <code>:w</code> to save, <code>:wq</code> to save then exit.</li>
<li>That should be enough to edit a file, but if you want to know more, type <code>:help</code> and there are links to on-line tutorials.</li>
</ul>
<p><a href='http://www.nointrigue.com/blog/wp-content/uploads/2007/08/vim.png' title='vim.png'><img src='http://www.nointrigue.com/blog/wp-content/uploads/2007/08/vim.thumbnail.png' alt='vim.png' /></a></p>
<p><strong>Installing software on your shared host</strong></p>
<p>If your server is a shared host, you can be pretty sure that you can&#8217;t install or modify the software installation on the server on a global level. You can, however, install additional software just for yourself in your home directory (which you can definitely write to!). If you don&#8217;t have SSH access to your server, you could try and recreate a similar environment to that on your server, compile the programs (using, perhaps, <a href="http://brianrose.net/columns/CrossToolsWin32.html">cross compilation</a>), and then upload the resulting executables like you would normally &mdash; let me know if you can get that to work!</p>
<p>Why would you want to install additional software? There are plenty of reasons for that. For example, you might want to run <a href="http://www.ruby-lang.org/">Ruby</a> scripts, but your host hasn&#8217;t updated the software installed since the dark ages. Alternatively, you might want to run software that isn&#8217;t typical for a shared web server; for example, I have <a href="http://subversion.tigris.org/">Subversion</a> (a version control system) and <a href="http://www.privoxy.org/">Privoxy</a> (a proxy server) installed. I also have a <a href="http://www.tug.org/texlive/">LaTeX installation</a> so I can get maths rendering in MediaWiki.</p>
<ol>
<li>Create a directory for downloading and compiling files: I call mine <code>src</code>, and it&#8217;s a subdirectory of my home directory ~. This is useful in case you make a mess; that way, you can use <code>rm -rf *</code> (see above) to obliterate everything in that directory and start again.</li>
<li>Download the source files: you will need to download the source files, and create the executable (binary file) yourself, instead of downloading the compiled executable. This will ensure that there are no problems installing or using the program. Open source projects will have the source code available. To download something to the current directory, use <code>wget <em>url</em></code>.</li>
<li>Unpack the source files: typically, the source file will have one of several extensions. If it ends in <code>.tgz</code> or <code>.tar.gz</code>, use <code>tar -xzvf <em>file</em></code>. If it ends in <code>.bz2</code>, use <code>tar -xjvf <em>file</em></code>. If it ends in <code>.zip</code>, use <code>unzip <em>file</em></code>.</li>
<li>Read the installation instructions: there&#8217;s often a <code>README</code> or <code>INSTALL</code> file amongst the files that were unpacked. Read it using <code>less</code> (see above).</li>
<li>Compile it: if there are installation instructions, follow those. However, if there&#8217;s a part where it asks you type in <code>./configure</code> (which is almost always), then you should type <code>./configure --prefix=$HOME</code> instead. This will make sure that your software is installed in your home directory. If there are no installation instructions, a typical sequence of commands is: <code>./configure --prefix=$HOME</code>, <code>make</code>, <code>make install</code>.</li>
<li>Test it out: your program will probably have been installed into <code>~/bin</code> <code>~/sbin</code>, where ~ is your home directory. Now, you&#8217;ll notice that you can only type the name of the program when your current directory (which you change using <code>cd</code>) is the directory where that executable resides. In order for the shell to find your newly installed program, regardless of what directory it resides in, you&#8217;ll need to add it to your <code>PATH</code> environment variable. To do this, you need to add a line to the <code>.bashrc</code> file that resides in your home directory (create one if it doesn&#8217;t exist). For example, my line looks like this: <code>export PATH=$PATH:~/bin:~/bin/tetex</code>, and that means that I&#8217;ve added <code>~/bin</code> and <code>~/bin/tetex</code> to the locations where the shell will search for programs; note the use of the colon to separate paths.</li>
</ol>
<p>That&#8217;s all for now folks! I hope the instructions are clear, and that your days of being a webmaster are more productive than before. If you want to learn more, Google is your friend.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nointrigue.com/blog/2007/08/11/installing-software-and-other-things-casual-webmasters-should-know/feed/</wfw:commentRss>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-nd/2.5/au/</creativeCommons:license>
	</item>
	</channel>
</rss>
