<?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>The Daily Build &#187; ssh</title>
	<atom:link href="http://blog.bstpierre.org/tag/ssh/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.bstpierre.org</link>
	<description>Software Development, version 3.0</description>
	<lastBuildDate>Fri, 03 Feb 2012 02:59:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>Tightening UFW Firewall Rules to Limit SSH Access</title>
		<link>http://blog.bstpierre.org/ufw-firewall-limit-ssh</link>
		<comments>http://blog.bstpierre.org/ufw-firewall-limit-ssh#comments</comments>
		<pubDate>Thu, 08 Dec 2011 23:54:21 +0000</pubDate>
		<dc:creator>Brian St. Pierre</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[firewall]]></category>
		<category><![CDATA[ssh]]></category>

		<guid isPermaLink="false">http://blog.bstpierre.org/?p=371</guid>
		<description><![CDATA[The auth.log on one of my servers (really, on all of the servers I have access to) is full of stuff like this: Dec 8 03:19:33 localhost sshd[4718]: User root from 10.1.2.3 not allowed [...] Dec 8 03:19:35 localhost sshd[4721]: Invalid user db2inst1 from 10.1.2.3 Dec 8 03:19:38 localhost sshd[4723]: User root from 10.1.2.3 not [...]]]></description>
			<content:encoded><![CDATA[<p>The auth.log on one of my servers (really, on <em>all</em> of the servers I have access to) is full of stuff like this:</p>
<pre><code>Dec  8 03:19:33 localhost sshd[4718]: User root from 10.1.2.3 not allowed [...]
Dec  8 03:19:35 localhost sshd[4721]: Invalid user db2inst1 from 10.1.2.3
Dec  8 03:19:38 localhost sshd[4723]: User root from 10.1.2.3 not allowed [...]</code>
</pre>
<p>fail2ban is configured to (temporarily) block these after a certain number of attempts, but they keep coming back. One particular IP address was hitting ssh constantly (except for the ban periods) for several days, so I added a rule to drop everything from that address &#8212; but this strategy isn&#8217;t scalable.</p>
<p>The simple, obvious solution is to only allow access from known hosts. It would be very rare that I need to access this server from anywhere except a small number of addresses. I started with a ufw (Ubuntu&#8217;s &#8220;uncomplicated firewall&#8221;) ruleset like this:</p>
<pre><code>% sudo ufw status
Status: active

To                         Action      From
--                         ------      ----
Anywhere                   DENY        10.1.2.3
Anywhere                   DENY        172.16.99.88
22                         ALLOW       Anywhere</code>
</pre>
<p>To avoid getting locked out, I added (temporarily) a crontab entry for root:</p>
<pre><code>*/15 * * * * /usr/sbin/ufw allow ssh</code></pre>
<p>This will allow access to ssh from any un-banned IP address (the current policy) every 15 minutes. Then I inserted a rule that allows access to ssh from my home ISPs netblock. (You can figure out the netblock by doing a whois lookup on your external IP address; you may need to add multiple netblocks if your ISP has several allocated. Be careful: it&#8217;s no fun to get locked out!) This action is safe because I have not yet removed global ssh access. Note that I&#8217;m using &#8220;insert 3&#8243; to add this rule at a specific position in the list.</p>
<pre><code>sudo ufw insert 3 allow proto tcp from 10.9.8.0/18 to any port 22</code></pre>
<p>And I added a rule to permit access from another server with a fixed IP I have access to (for the rare case where I need to access this server when I&#8217;m not at home):</p>
<p><code>sudo ufw insert 3 allow proto tcp from 172.17.101.102 to any port 22</code></p>
<p>Now my ruleset looks like:</p>
<pre><code>Status: active

To                         Action      From
--                         ------      ----
Anywhere                   DENY        10.1.2.3
Anywhere                   DENY        172.16.99.88
22/tcp                     ALLOW       172.17.101.102
22/tcp                     ALLOW       10.9.8.0/18
22                         ALLOW       Anywhere
</code></pre>
<p>So far, so good, but ssh access is still permitted from anywhere &#8212; because of that last rule. This is the dangerous part&#8230; you could get locked out if you haven&#8217;t set the rules correctly. (You set up that crontab entry, right?)</p>
<pre><code>sudo ufw delete allow ssh</code></pre>
<p>Wait for the prompt&#8230; hooray, I&#8217;m still connected! After checking that I can access ssh from home and the other server, I know it&#8217;s safe to remove the crontab job. (If the cron job has already fired, you&#8217;ll need to rerun the <code>ufw delete allow ssh</code> command.)</p>
<p>At this point I can delete the first two rules that ban specific IPs, since they&#8217;re outside my netblock and won&#8217;t be allowed anyway.</p>
<p>Now I can enjoy quieter logs without all those access attempts from China and Croatia!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.bstpierre.org/ufw-firewall-limit-ssh/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using SSH for IPv6-enabled HTTP Proxying</title>
		<link>http://blog.bstpierre.org/using-ssh-for-ipv6-enabled-http-proxying</link>
		<comments>http://blog.bstpierre.org/using-ssh-for-ipv6-enabled-http-proxying#comments</comments>
		<pubDate>Fri, 11 Nov 2011 16:50:26 +0000</pubDate>
		<dc:creator>Brian St. Pierre</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[network]]></category>
		<category><![CDATA[ipv6]]></category>
		<category><![CDATA[ssh]]></category>

		<guid isPermaLink="false">http://blog.bstpierre.org/?p=358</guid>
		<description><![CDATA[My ISP has apparently made no progress whatsoever with IPv6, but I&#8217;ve got an IPv6 enabled VPS. SSH makes it trivial to use that VPS as a SOCKS5 proxy. Just do: ssh -D 8080 myvps.example.com Then set your browser&#8217;s SOCKS proxy to localhost:8080. In Firefox on Linux, this is Edit &#62; Preferences &#62; Advanced &#62; [...]]]></description>
			<content:encoded><![CDATA[<p>My ISP has apparently made no progress whatsoever with IPv6, but I&#8217;ve got an IPv6 enabled VPS.</p>
<p>SSH makes it trivial to use that VPS as a SOCKS5 proxy. Just do:</p>
<p><code>ssh -D 8080 myvps.example.com</code></p>
<p>Then set your browser&#8217;s SOCKS proxy to localhost:8080. In Firefox on Linux, this is Edit &gt; Preferences &gt; Advanced &gt; Network tab &gt; (Connection) Settings &gt; Manual Proxy Configuration. Leave <em>all fields blank</em> except for SOCKS Host and Port &#8212; localhost and 8080, respectively. Choose SOCKS5. Then browse to about:config and change <code>change network.proxy.socks_remote_dns</code> to true. This tells Firefox to ask the proxy to resolve names instead of trying to resolve them using your ISP. Chrome worked for me without hassle.</p>
<p>Go to <a href="http://test-ipv6.com/">test-ipv6.com</a> to test that it works. If your results from test-ipv6.com indicate that IPv6 name lookups are failing, make sure you&#8217;ve got that about:config setting mentioned above changed.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.bstpierre.org/using-ssh-for-ipv6-enabled-http-proxying/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Use SSH to Forward Multiple Protocols to Multiple Machines</title>
		<link>http://blog.bstpierre.org/ssh-forward-multiple-protocols-to-multiple-machines</link>
		<comments>http://blog.bstpierre.org/ssh-forward-multiple-protocols-to-multiple-machines#comments</comments>
		<pubDate>Fri, 04 Dec 2009 16:03:33 +0000</pubDate>
		<dc:creator>Brian St. Pierre</dc:creator>
				<category><![CDATA[ssh]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[tool]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://blog.bstpierre.org/?p=239</guid>
		<description><![CDATA[Let's say you have a half-dozen machines at work you want to log into. Instead of setting up a remote forwarding connection from each of those machines, you can have the connection from your main machine perform multiple forwardings instead of just one. This even works if some of the machines don't support ssh.]]></description>
			<content:encoded><![CDATA[<p><em>(This is part five in a <a href="../category/tools/ssh">series of posts on ssh</a>.)</em></p>
<p>Let&#8217;s say you have a half-dozen machines at work you want to log into. Instead of setting up a <a href="http://blog.bstpierre.org/ssh-remote-port-forwarding-tunnels">remote forwarding connection</a> from each of those machines, you can have the connection from your main machine perform multiple forwardings instead of just one. This even works if some of the machines don&#8217;t support ssh.</p>
<p>It shouldn&#8217;t surprise you at this point that you can do this with your config file. On your work machine, you might have something like:</p>
<pre>Host tunnel
  HostName cloud.example.com
  User mycloudusername
  IdentityFile ~/.ssh/id_dsa
  Port 22
  RSAAuthentication yes
  PubkeyAuthentication yes
  ExitOnForwardFailure yes
  # tunnel ssh to myworkmachine
  RemoteForward 4022 localhost:22
  # tunnel remote desktop to mywindowsbox via myworkmachine
  RemoteForward 5389 192.168.4.10:3389
  # tunnel http to mywindowsbox via myworkmachine
  RemoteForward 5080 192.168.4.10:80
  # tunnel remote desktop to otherwindowsbox via myworkmachine
  RemoteForward 6389 192.168.4.11:3389
  # tunnel ssh to workserver via myworkmachine
  RemoteForward 7022 192.168.4.2:22</pre>
<p>You can add a bunch of forwardings as shown above. Each entry will open the given port on cloud and forward it to the specified port on the specified machine. Now when you run &#8220;ssh tunnel&#8221; on your work machine, it will connect to cloud and set up the five port forwardings specified in your config file.</p>
<p>Then when logged in to cloud.example.com, you can do, for example, &#8220;ssh -p 7022 myserverlogin@localhost&#8221; to log into the machine called workserver.</p>
<p>If you mirror the remote forwardings in your home config file as local forwardings, then when you &#8220;ssh work&#8221; from home you can remote desktop to a windows machine from your home pc by doing &#8220;rdesktop -u myworkwinuser localhost:5389&#8243; and it will use the tunnel. (The connection will go from your home pc to cloud, to myworkmachine, to mywindowsbox.) The windows machine does not need to know anything about ssh.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.bstpierre.org/ssh-forward-multiple-protocols-to-multiple-machines/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Open an SSH Tunnel in Four Seconds or Less</title>
		<link>http://blog.bstpierre.org/open-an-ssh-tunnel-in-four-seconds-or-less</link>
		<comments>http://blog.bstpierre.org/open-an-ssh-tunnel-in-four-seconds-or-less#comments</comments>
		<pubDate>Thu, 03 Dec 2009 15:28:47 +0000</pubDate>
		<dc:creator>Brian St. Pierre</dc:creator>
				<category><![CDATA[ssh]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[tool]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://blog.bstpierre.org/?p=233</guid>
		<description><![CDATA[As I mentioned in a previous post on ssh configuration, your config file can specify a variety settings for each server. In fact, the Hosts you use don't even have to exist! Consider the following snippet in your ~/.ssh/config.]]></description>
			<content:encoded><![CDATA[<p><em>(This is part four in a <a href="../category/tools/ssh">series of posts on ssh</a>.)</em></p>
<p>As I mentioned in a previous post on <a href="http://blog.bstpierre.org/configure-ssh-username">ssh configuration</a>, your config file can specify a variety settings for each server.</p>
<p>In fact, the Hosts you use don&#8217;t even have to exist! (The HostName is the important part.) Consider the following snippet in your ~/.ssh/config.</p>
<pre>#
Host work
  HostName localhost
  User myworklogin
  IdentityFile ~/.ssh/id_dsa
  Port 4022
  RSAAuthentication yes
  PubkeyAuthentication yes
  LocalForward 4022 localhost:4022</pre>
<p>I&#8217;m going to assume remote forwarding is set up and the connection is open from work to cloud as described in <a href="http://blog.bstpierre.org/ssh-remote-port-forwarding-tunnels">this post on remote forwarding</a>; and you&#8217;ve got local forwarding set up from home to cloud as described in this post on <a href="http://blog.bstpierre.org/local-ssh-forwarding">local port forwarding</a>.</p>
<p>Now you can do &#8220;ssh work&#8221; from your home pc, and it will automatically log you into your work pc with the right credentials using the tunnel on cloud.example.com. And the scp example above simplifies to &#8220;scp work:/tmp/foo.txt ~/foo.txt&#8221; &#8212; you don&#8217;t have to remember the forwarded port numbers.</p>
<p>Typing &#8220;ssh work&#8221; is nine keystrokes (eight letters plus enter). If you can type 40 wpm, that&#8217;s 200 keystrokes per minute, or 3.33 keystrokes per second, which means you can open the tunnel in four seconds!</p>
<p>If you add &#8220;alias ssw=&#8217;ssh work&#8217;&#8221; to your ~/.bashrc, you&#8217;re down to four keystrokes.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.bstpierre.org/open-an-ssh-tunnel-in-four-seconds-or-less/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Use Local SSH Forwarding to Reduce the Number of Manual Hops</title>
		<link>http://blog.bstpierre.org/local-ssh-forwarding</link>
		<comments>http://blog.bstpierre.org/local-ssh-forwarding#comments</comments>
		<pubDate>Wed, 02 Dec 2009 15:12:19 +0000</pubDate>
		<dc:creator>Brian St. Pierre</dc:creator>
				<category><![CDATA[ssh]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[tool]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://blog.bstpierre.org/?p=219</guid>
		<description><![CDATA[Local port forwarding is the same as remote port forwarding but works in the opposite direction. An example is the clearest way to explain...]]></description>
			<content:encoded><![CDATA[<p><em>(This is part three in a <a href="../category/tools/ssh">series of posts on ssh</a>.)</em></p>
<p>Local port forwarding is the same as <a title="How to Use SSH Remote Port Forwarding to Set Up Secure Tunnels" href="http://blog.bstpierre.org/ssh-remote-port-forwarding-tunnels">remote port forwarding</a> but works in the opposite direction. An example is the clearest way to explain.</p>
<p>Assuming you&#8217;ve done the steps in the previous posts, then at home you can run &#8220;ssh -L 4022:localhost:4022 me@cloud.example.com&#8221;. This listens on TCP port 4022 on your home machine. Any connections there will be forwarded through the ssh connection to port 4022 on cloud&#8230; which, as we recall, gets forwarded to port 22 (ssh) at work. If you leave this connection open, you can run &#8220;ssh -p 4022 localhost&#8221; on your home machine and it will connect to work in just one hop. This means that you can use scp to copy files from home to work or vice versa. For example, &#8220;scp -P 4022 localhost:/tmp/foo.txt ~/foo.txt&#8221; will copy a file from work to home. (<em>Note: scp needs capital &#8220;-P&#8221; to give the port. I got it wrong the first time.</em>)</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.bstpierre.org/local-ssh-forwarding/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to Use SSH Remote Port Forwarding to Set Up Secure Tunnels</title>
		<link>http://blog.bstpierre.org/ssh-remote-port-forwarding-tunnels</link>
		<comments>http://blog.bstpierre.org/ssh-remote-port-forwarding-tunnels#comments</comments>
		<pubDate>Tue, 01 Dec 2009 14:35:17 +0000</pubDate>
		<dc:creator>Brian St. Pierre</dc:creator>
				<category><![CDATA[ssh]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[tool]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://blog.bstpierre.org/?p=215</guid>
		<description><![CDATA[Ssh tunneling can be a bit mind bending at first, but it's simple when you get used to it.]]></description>
			<content:encoded><![CDATA[<p><em>(This is part two in a <a href="http://blog.bstpierre.org/category/tools/ssh">series of posts on ssh</a>.)</em></p>
<p>Ssh tunneling can be a bit mind bending at first, but it&#8217;s simple when you get used to it. Assume that you&#8217;re trying to ssh between two sites that do not allow incoming ssh. Maybe your IT at work is unenlightened and doesn&#8217;t have an ssh gateway. And your ISP has braindead configuration rules that don&#8217;t allow incoming ssh or they make it difficult.</p>
<p>What you need to get around this is a server &#8220;in the cloud&#8221; that permits ssh logins. This could be a hosting server that you pay for, or even a friend with an enlightened ISP who will give you a login account.</p>
<p>On your work PC, use ssh to login to the &#8220;cloud&#8221; server. Using the &#8220;-R&#8221; argument, you tell ssh to listen on a TCP port on the cloud server. Any connection coming in to this server will be forwarded back through the ssh connection to the TCP port you specify. For example, on mymachine.work.com, &#8220;ssh -R 4022:localhost:22 me@cloud.example.com&#8221; tells ssh to listen on cloud&#8217;s port 4022. Incoming connections to that port on cloud will be forwarded to port 22 (ssh) on mymachine.</p>
<p>By default, ssh will only listen to port 4022 on cloud&#8217;s localhost interface. So to log in to work, you will first need to log into cloud, and then use &#8220;ssh -p 4022 myworklogin@localhost&#8221; to log into work.</p>
<p>We&#8217;ll work around this limitation in the next post in this series.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.bstpierre.org/ssh-remote-port-forwarding-tunnels/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Tell SSH Who You Are</title>
		<link>http://blog.bstpierre.org/configure-ssh-username</link>
		<comments>http://blog.bstpierre.org/configure-ssh-username#comments</comments>
		<pubDate>Mon, 30 Nov 2009 15:11:10 +0000</pubDate>
		<dc:creator>Brian St. Pierre</dc:creator>
				<category><![CDATA[ssh]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[tool]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://blog.bstpierre.org/?p=222</guid>
		<description><![CDATA[Do you log in to several servers with different usernames via ssh? Save typing by telling ssh which username to use on each server.]]></description>
			<content:encoded><![CDATA[<p>Ssh has amazing capabilities that you probably aren&#8217;t using on a daily basis.</p>
<p>The capability that you probably aren&#8217;t using, and the easiest to use, is customizing your config file (in ~/.ssh/config) for the various servers you log into.</p>
<p>For example, I frequently log into about ten different servers using at least four different usernames. By default, if I type &#8220;ssh server&#8221; the client will use my login name on the client machine to try to log into the server &#8212; which is usually wrong. Instead you can <a href="http://superuser.com/questions/64996/how-to-make-ssh-log-in-as-the-right-user">tell your ssh client which username to use on each server</a>. (Thanks to <a href="http://wblinks.com/">Rich Adams</a> for the tip.)</p>
<p>You can customize a variety of settings &#8212; not just the username. For example, I specify a different identity file for a couple of servers.</p>
<p>This saves a bunch of typing and occasional confusion. (By avoiding login errrors as I try to log into a server using the wrong username and can&#8217;t figure out why my password isn&#8217;t working&#8230;)</p>
<p><em>(This is the first post in <a href="../category/tools/ssh">series of posts about how to get the most out of ssh</a>. Make sure you don&#8217;t miss the rest of the series: <a href="http://feeds2.feedburner.com/TheDailyBuild">subscribe to my feed</a> or <a href="http://twitter.com/bstpierre">follow me on twitter</a>.)</em></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.bstpierre.org/configure-ssh-username/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

