<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>OpenSSH on Wimpy's World</title><link>https://blog.wimpys.world/tags/openssh/</link><description>Recent content in OpenSSH on Wimpy's World</description><generator>Hugo -- gohugo.io</generator><language>en-gb</language><managingEditor>martin@wimpress.com (Martin Wimpress)</managingEditor><webMaster>martin@wimpress.com (Martin Wimpress)</webMaster><lastBuildDate>Mon, 26 Nov 2012 13:14:09 +0000</lastBuildDate><atom:link href="https://blog.wimpys.world/tags/openssh/rss.xml" rel="self" type="application/rss+xml"/><item><title>SSH brute force defense</title><link>https://blog.wimpys.world/posts/ssh-brute-force-defense/</link><pubDate>Mon, 26 Nov 2012 13:14:09 +0000</pubDate><author>martin@wimpress.com (Martin Wimpress)</author><guid>https://wimpysworld.com/posts/ssh-brute-force-defense/</guid><description>&lt;p&gt;I have several VPS hosts with different providers using different
virtualisation platforms. Naturally I have &lt;a href="http://www.openssh.org/"&gt;OpenSSH&lt;/a&gt;
running on these VPS hosts and deploy either &lt;a href="http://denyhosts.sourceforge.net/"&gt;DenyHosts&lt;/a&gt;
or &lt;a href="http://www.fail2ban.org/"&gt;Fail2Ban&lt;/a&gt; to add an extra security layer to
thwart SSH brute force attacks and other abuse.&lt;/p&gt;
&lt;p&gt;DenyHosts blocks brute force attacks by adding offending IP addresses to
&lt;code&gt;/etc/hosts.deny&lt;/code&gt;. It therefore requires the SSH server is configured with
&lt;code&gt;tcp_wrappers&lt;/code&gt;. Arch Linux &lt;a href="https://www.archlinux.org/news/dropping-tcp_wrappers-support/"&gt;dropped support for tcp_wrappers&lt;/a&gt;
so DenyHosts is not suitable for Arch. Fail2Ban supports blocking via &lt;code&gt;iptables&lt;/code&gt; and/or
&lt;code&gt;tcp_wrappers&lt;/code&gt; and can also block offending hosts that are abusing services other than just &lt;code&gt;sshd&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id="denyhosts-on-ubuntu"&gt;DenyHosts on Ubuntu&lt;/h2&gt;
&lt;p&gt;Here is a simple example for DenyHosts on Ubuntu Lucid 10.04 LTS Server.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;sudo apt-get install denyhosts
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;That&amp;rsquo;s it. The default configuration will provide suitable prevention, but do
take a look at &lt;code&gt;/etc/denyhosts.conf&lt;/code&gt; for a full run down of all available options.
I use the defaults with the following exceptions:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-ini" data-lang="ini"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="na"&gt;PURGE_DENY&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;5d&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="na"&gt;PURGE_THRESHOLD&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;2&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="na"&gt;ADMIN_EMAIL&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="na"&gt;SYSLOG_REPORT&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;NO&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;You might want to consider whitelisting some of your own IP address. Create a
file called &lt;code&gt;allowed-hosts&lt;/code&gt; in &lt;code&gt;/var/lib/denyhosts&lt;/code&gt; and list each of your
&amp;ldquo;trusted&amp;rdquo; IP addresses.&lt;/p&gt;
&lt;p&gt;DenyHosts can be restarted by executing:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;sudo /etc/init.d/denyhosts restart
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id="fail2ban-on-arch-linux"&gt;Fail2Ban on Arch Linux&lt;/h2&gt;
&lt;p&gt;Fail2Ban now supports systemd.&lt;/p&gt;
&lt;p&gt;Configuration files are stored in &lt;code&gt;/etc/fail2ban&lt;/code&gt;. General configuration is
&lt;code&gt;/etc/fail2ban/jail.conf&lt;/code&gt;, but this file might be overwritten in the future. To
preserve customisations, create &lt;code&gt;/etc/fail2ban/jail.local&lt;/code&gt; and add your local
configuration settings to it. In the example below some IP addresses are whitelisted
and the default backend is set to systemd:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-ini" data-lang="ini"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;[DEFAULT]&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="na"&gt;ignoreip&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;172.16.0.2/32&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="na"&gt;backend&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;systemd&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Next create a custom sshd configuration in &lt;code&gt;/etc/fail2ban/jail.d/sshd.conf&lt;/code&gt;
which will temporarily ban offending IP addresses.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-ini" data-lang="ini"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# fail2ban SSH&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# block ssh after 3 unsuccessful login attempts for 10 minutes&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;[sshd]&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="na"&gt;enabled&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;true&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="na"&gt;action&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;iptables[chain=INPUT, protocol=tcp, port=22, name=sshd]&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="na"&gt;maxRetry&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;3&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="na"&gt;findtime&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;600&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="na"&gt;bantime&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;600&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="na"&gt;port&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;22&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The &amp;lsquo;action&amp;rsquo; creates DROP rule in iptables after 3 unsuccessful login
attempts, valid for 10 minutes (bantime). Findtime defines time frame in which
fail2ban will count failed login attempts from logs, so if one IP has 3
incorrect login attempts in last 10 minutes, it will be banned.&lt;/p&gt;
&lt;p&gt;Enable and start the Fail2Ban daemon.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;sudo systemctl &lt;span class="nb"&gt;enable&lt;/span&gt; fail2ban
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;sudo systemctl start fail2ban
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Basic commands for fail2ban-client:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;fail2ban-client start sshd
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;fail2ban-client stop sshd
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;fail2ban-client reload sshd
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;fail2ban-client status sshd
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;fail2ban-client &lt;span class="nb"&gt;set&lt;/span&gt; sshd unbanip 172.16.0.4
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;See the &lt;a href="https://wiki.archlinux.org/index.php/Fail2ban"&gt;Arch Linux Fail2Ban Wiki page&lt;/a&gt;
for more details.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;References&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://krisko210.blogspot.co.uk/2014/03/setting-up-fail2ban.html"&gt;http://krisko210.blogspot.co.uk/2014/03/setting-up-fail2ban.html&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="ssh-best-practice"&gt;SSH best practice&lt;/h2&gt;
&lt;p&gt;DenyHosts and Fail2Ban do not provide complete protection against SSH brute
force attacks. I employ other SSH best practice to better secure the SSH
services I expose to the Internet, and so should you. The following is a
good reference.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://www.ibm.com/developerworks/aix/library/au-sshsecurity/index.html"&gt;Getting started with SSH security and configuration&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="other-ssh-brute-force-prevention-tools"&gt;Other SSH brute force prevention tools&lt;/h2&gt;
&lt;p&gt;In the interests of fairness, other SSH brute force preventation tools are
available.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://www.sshguard.net/"&gt;Sshgaurd&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://cgi.csc.liv.ac.uk/~greg/sshdfilter/"&gt;sshdfilter&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://help.ubuntu.com/community/UFW"&gt;Uncomplicated Firewall&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://wiki.archlinux.org/index.php/Uncomplicated_Firewall#Rate_Limiting_with_ufw"&gt;Rate Limiting&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Do you know any other tools that help prevent SSH brute force attacks?&lt;/p&gt;</description><summary>Deploy DenyHosts or Fail2Ban to better prevent SSH brute force attacks.</summary></item><item><title>SSHMenu - SSH Connection Management</title><link>https://blog.wimpys.world/posts/sshmenu-ssh-connection-management/</link><pubDate>Tue, 26 Feb 2008 13:21:28 +0000</pubDate><author>martin@wimpress.com (Martin Wimpress)</author><guid>https://wimpysworld.com/posts/sshmenu-ssh-connection-management/</guid><description>&lt;p&gt;We have a reasonable number of Debian servers at work and as a result I &lt;code&gt;ssh&lt;/code&gt;
into servers about as many times as I visit Google. I have been using
Profiles in gnome-terminal to manage my ssh connections, which is fine but
requires I already have a terminal open to initiate a new server connection.
Enter &lt;a href="http://sshmenu.sourceforge.net/"&gt;SSHMenu&lt;/a&gt;, a GNOME panel applet that
keeps all your regular SSH connections within a single mouse click.&lt;/p&gt;
&lt;p&gt;I couldn&amp;rsquo;t be arsed adding up a new repo for one application, so here are my
quick and dirty install steps.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;wget http://sshmenu.sourceforge.net/debian/dists/stable/contrib/binary-all/sshmenu_3.15-1_all.deb
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;wget http://sshmenu.sourceforge.net/debian/dists/stable/contrib/binary-all/sshmenu-gnome_3.15-1_all.deb
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;sudo gdebi -n sshmenu_3.15-1_all.deb
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;sudo gdebi -n sshmenu-gnome_3.15-1_all.deb
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;I have taken to using &lt;code&gt;gdebi&lt;/code&gt; to install local deb packages as it resolves and
installs dependencies. Now add SSHMenu to a GNOME panel and configure
your ssh connections. If SSHMenu isn&amp;rsquo;t listed in the GNOME panel applets yet,
then you can force a refresh with the rather heavy handed&amp;hellip;&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;killall gnome-panel
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</description><summary>Managing SSH connections from a GNOME panel applet</summary></item></channel></rss>