<?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>Random and Irrelevant &#187; SSH</title>
	<atom:link href="http://sgp.me.uk/tag/ssh/feed/" rel="self" type="application/rss+xml" />
	<link>http://sgp.me.uk</link>
	<description>Sam Pearson&#039;s weblog - irrelevant content randomly updated</description>
	<lastBuildDate>Fri, 18 Nov 2011 18:06:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>More on securing SSH</title>
		<link>http://sgp.me.uk/2005/11/23/securing-sshd-rewritten/</link>
		<comments>http://sgp.me.uk/2005/11/23/securing-sshd-rewritten/#comments</comments>
		<pubDate>Wed, 23 Nov 2005 12:11:10 +0000</pubDate>
		<dc:creator>Sam</dc:creator>
				<category><![CDATA[Geekery]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[SSH]]></category>

		<guid isPermaLink="false">http://sgp.me.uk/2005/11/23/securing-sshd-rewritten</guid>
		<description><![CDATA[Just a brief post to flag that I&#8217;ve re-written my earlier post on securing SSH servers to include quite a lot more detail. I&#8217;d be very interested in any feedback and suggestions on this, particularly stuff I&#8217;ve missed out or &#8230; <a href="http://sgp.me.uk/2005/11/23/securing-sshd-rewritten/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Just a brief post to flag that I&#8217;ve re-written my earlier post on <a href="http://sgp.me.uk/weblog/2005/07/11/securing-sshd">securing SSH servers</a> to include quite a lot more detail.  I&#8217;d be very interested in any feedback and suggestions on this, particularly stuff I&#8217;ve missed out or any mistakes that may have slipped in, so please <a href="http://sgp.me.uk/contact/">get in touch</a> if you&#8217;ve any comments (I really must implement a commenting system here at some point).</p>
]]></content:encoded>
			<wfw:commentRss>http://sgp.me.uk/2005/11/23/securing-sshd-rewritten/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Brute force ssh password attacks</title>
		<link>http://sgp.me.uk/2005/08/25/ssh-attacks/</link>
		<comments>http://sgp.me.uk/2005/08/25/ssh-attacks/#comments</comments>
		<pubDate>Thu, 25 Aug 2005 10:48:56 +0000</pubDate>
		<dc:creator>Sam</dc:creator>
				<category><![CDATA[Geekery]]></category>
		<category><![CDATA[iptables]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[SSH]]></category>

		<guid isPermaLink="false">http://sgp.me.uk/2005/08/25/ssh-attacks</guid>
		<description><![CDATA[Since opening my <a href="http://www.openssh.com/">SSH</a> server at home to the internet yesterday - less than 24 hours ago - there have been 2883 failed attempts to log in from two ip addresses... <a href="http://sgp.me.uk/2005/08/25/ssh-attacks/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Since opening my <a href="http://www.openssh.com/">SSH</a> server at home to the internet yesterday &#8211; less than 24 hours ago &#8211; there have been 2883 failed attempts to log in from two ip addresses: <code>209.183.190.11</code> and <code>59.120.13.130</code>.  That makes me nervous, even though I&#8217;m reasonably confident that it&#8217;s secure due to password authentication being turned off and the following two handy <code>iptables</code> rules in force:</p>
<pre><code>iptables -A INPUT -p tcp -m state --state NEW --dport 22 \
 -m recent --update --seconds 15 -j DROP 

iptables -A INPUT -p tcp -m state --state NEW --dport 22 \
 -m recent --set -j ACCEPT</code></pre>
<p>I got this idea from <a href="http://groups.google.com/group/alt.os.linux.slackware/msg/6dd3ce3163d2f524" rel="via">a post to alt.os.linux.slackware</a>.  These rules use the <a href="http://www.netfilter.org/documentation/HOWTO//netfilter-extensions-HOWTO-3.html#ss3.16" title="Netfilter Extensions HOWTO: recent patch">recent extension</a> to <code>iptables</code> to track attempted SSH connections and drop any that come from the same IP within 15 seconds.  If you miss-type your passphrase, you just have to remember to hang back for a few seconds before retrying to avoid getting caught out.  You could jump to a custom chain that logged such connections before dropping them if you felt the need to monitor the effectiveness of the rule &#8211; although the scripts usually just stop trying after a few connection attempts are dropped.</p>
]]></content:encoded>
			<wfw:commentRss>http://sgp.me.uk/2005/08/25/ssh-attacks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Securing sshd</title>
		<link>http://sgp.me.uk/2005/07/11/securing-sshd/</link>
		<comments>http://sgp.me.uk/2005/07/11/securing-sshd/#comments</comments>
		<pubDate>Mon, 11 Jul 2005 16:05:46 +0000</pubDate>
		<dc:creator>Sam</dc:creator>
				<category><![CDATA[Geekery]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[SSH]]></category>

		<guid isPermaLink="false">http://sgp.me.uk/2005/07/11/securing-sshd</guid>
		<description><![CDATA[I've decided to collate what I've picked-up on this topic as much of the advice I've found on the net is rather fragmented. <a href="http://sgp.me.uk/2005/07/11/securing-sshd/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve decided to collate what I&#8217;ve picked-up on this topic as much of the advice I&#8217;ve found on the net is rather fragmented.  Following these instructions is no substitute for reading the documentation with your <abbr title="Secure SHell">SSH</abbr> server and should be followed at your own risk &#8211; this is very much a brief round-up and not a detailed HOWTO.  Anyway, having any services publicly available to the internet is a security risk and no amount of preparation can provide 100% certainty against compromise.</p>
<ol>
<li>Is your version of SSH up to date?  Do you have a system for ensuring that it is kept up to date?  None of the tips in this post will be of any use if your server has any known vulnerabilities (or any largely unknown ones for that matter, although the only way to effectively protect against these is to give up and unplug the network cable <img src='http://sgp.me.uk/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />   The same should apply for all the other services you make available to the internet as having a tightly locked-down SSH daemon won&#8217;t be much use if your mail and web servers are full of holes.  Make sure you have a reasonable understanding of what it takes to secure your machine &#8211; see the related reading section below for some starting points.</li>
<li>Work out how <code>sshd</code> is started and with what command line options.  For example, are you sure you know what configuration file the server is using?  The default is <code>/etc/ssh/sshd_config</code>, but it is possible to change this using the <code>-f</code> switch on the command line used to start the server.  Check your startup scripts to be sure.</li>
<li>Audit the user accounts on your system.  This is the sort of more general security measure that you should be taking anyway, but it&#8217;s worth mentioning here.  Some common account names are targeted by the automated brute-force password cracker scripts out there, so be careful of accounts with names like <code>admin</code>, <code>user</code>, <code>guest</code>, <code>test</code>, etc.  Where possible also make sure that the system accounts required by some services have no passwords set and have something sensible set as their shells like <code>/bin/false</code>.</li>
<li>Think carefully about from where you need to allow access to the server: does every machine on the net really need to be able to connect to it?  You can use the <code>/etc/hosts.allow</code> and <code>/etc/hosts.deny</code> files to control access (see <code>man hosts_access</code>), as well as setting up <code>iptables</code> rules only permit access from trusted IPs or ranges of IPs, for example (assuming you drop incoming packets by default):
<pre><code>iptables -A INPUT -s $TRUSTED_IP -p tcp --dport 22 -j ACCEPT</code></pre>
</li>
<li>Carefully read the relevant manual pages, particularly <code>sshd</code> and <code>sshd_config</code>.  Then read your <code>/etc/ssh/sshd_config</code> file &#8211; do not assume that your vendor or distribution has not altered any of the default variables.  Some variables to pay particular attention to include:
<ul>
<li><code>Protocol</code> &#8211; set this to <b>2</b> so as to not allow connections to fall back on protocol 1.</li>
<li>Make sure that <code>PermitRootLogin</code> in set to <b>no</b>.</li>
<li>Set <code>PasswordAuthentiction</code> to <b>no</b> whenever possible.</li>
<li>Set <code>PubkeyAuthentication</code> to <b>yes</b> (default) and set up keypairs for users (see <code>man ssh-keygen</code> and <code>man ssh-agent</code>).</li>
<li>Set <code>PermitEmptyPasswords</code> to <b>no</b> (default).</li>
<li>Set <code>StrictModes</code> to <b>yes</b> (default).</li>
<li>Set <code>UsePrivilageSeparation</code> to <b>yes</b> (default).</li>
</ul>
<p>Hopefully most of these variables will be in the states described.  Note that some linux distributions use <acronym title="Pluggable Authentication Modules">PAM</acronym> to authenticate users connecting to the SSH server.  This is beyond the scope of this article &#8211; see the <code>UsePAM</code> directive in the <code>sshd_config</code> manpage and the <a href="http://www.kernel.org/pub/linux/libs/pam/">Linux-PAM</a> website for more information on this.</li>
<li>You can use the <code>AllowUsers</code> and <code>AllowGroups</code> directives and their <code>DenyUsers</code> and <code>DenyGroups</code> counterparts to limit access to trusted users or deny access to system accounts or untrusted users.  Particularly useful if you need to allow password-based authentication.</li>
<li>If you need to allow blanket access to the server from the internet, investigate methods for throttling large numbers of simultaneous incoming connections.  Two worth investigating are:
<ul>
<li>The built-in <code>MaxStartups</code> directive in the <code>sshd_config</code> file.  This sets the number of unauthenticated connections that are allowed at any one time before the server starts ignoring new connection attempts, and can be useful if you find your server is being targeted by brute force attackers making lots and lots of simultaneous or near-simultaneous connections.  Read the <code>sshd_config</code> man page for more information on this.</li>
<li>Use the <a href="http://www.netfilter.org/documentation/HOWTO//netfilter-extensions-HOWTO-3.html#ss3.16">recent extension</a> to <code>iptables</code> to track incoming connections and drop any from the same IP within a given number of seconds.  This is very effective aganist the brute-force password crackers:
<pre><code>iptables -A INPUT -p tcp -m state --state NEW --dport 22 \
 -m recent --update --seconds 15 -j DROP 

iptables -A INPUT -p tcp -m state --state NEW --dport 22 \
 -m recent --set -j ACCEPT</code></pre>
</li>
</ul>
</li>
<li>Some people may recommend moving the server to an unusual port by setting the <code>Port</code> directive in <code>sshd_config</code>, others may suggest implementing <a href="http://www.portknocking.org/" title="Martin Krzywinski's port knocking pages">port knocking</a> to control access.  Although these solutions may afford you some additional security, the former is just a form of <a href="http://en.wikipedia.org/wiki/Security_through_obscurity" title="Wikipedia: Security through obscurity">security through obscurity</a>, although it&#8217;s probably quite effective against the automated scanners.   The latter method is not without <a href="http://software.newsforge.com/article.pl?sid=04/08/02/1954253" title="NewsForge: A critique of port knocking">detractors</a>, but can also be useful.  Anyway, neither should be used as a substitute for other security measures, so I&#8217;ll say no more about them here.</li>
</ol>
<p>This article has been re-written from a stub that really just referenced the article that inspired it, <a href="http://www.unix-girl.com/blog/archives/001568.html" title="kasia in a nutshell: Secure access to your server checklist" rel="via">Securing access to your server checklist</a>.  <a href="http://sgp.me.uk/contact/">Feedback</a> is very welcome.</p>
<h3 id="sshd-related">Related reading</h3>
<ul>
<li><a href="http://www.openssh.com/index.html">The OpenSSH hompage</a></li>
<li><a href="http://www.netfilter.org/">The netfilter/iptables homepage</a></li>
<li><a href="http://www.tldp.org/HOWTO/Security-HOWTO/">The Linux Security HOWTO</a></li>
<li><a href="http://www.kernel.org/pub/linux/libs/pam/">The Linux-PAM homepage</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://sgp.me.uk/2005/07/11/securing-sshd/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

