TechRepublic : A ZDNet Tech Community

IT Security

Host: Chad Perrin
Contact

Protect SSH from brute force password-cracking attacks

In the midst of ensuring you don’t have any unnecessary services running while securing a Unix-like system from outside attacks — whether a proprietary UNIX system, a free BSD Unix system, or a Linux distribution — one of the services you’ll almost certainly come across is the SSH daemon. In most cases, this will mean OpenSSH, and you’ll want to make sure you can access a server remotely, particularly in cases where your servers are running “headless” (without monitor and keyboard).

There are automated systems out there running 24/7 that are attempting to access any computers on port 22 via brute force attacks to get past SSH password protection. If you check your /var/log/auth.log file on any system connected directly to the Internet, or perhaps connected to an open wireless access point in a coffee shop, before long you’ll likely start seeing entries at the end of the file that look something like this:

Oct 30 19:07:33 local_host sshd[6906]: error: PAM: authentication error for root from remote_host

There are a number of things you can do to cut down on the incidence of that and to reduce the likelihood of getting your system compromised by these blind attacks. For instance, a sufficiently complex password is essentially uncrackable at current technology levels. Oh, sure, any password can be cracked “eventually,” but that eventuality may take more than a century to complete with the computing resources at your fingertips today.

Another example is to simply configure SSH to listen on a port other than 22. For instance, you might assign it to listen to port 1138 (in honor of George Lucas’ 1967 movie, THX 1138 4EB). To do so, simply change the Port line in the /etc/ssh/sshd_config file to show the new port number you want to use — and be sure to use that port number when connecting from a remote system. After editing, that line in sshd_config should look something like this:

Port 1138

Port knocking can be used to provide an additional layer of security and keep the common malicious security crackers from even finding out you have an open SSH port. OpenSSH allows use of key-based authentication instead of password authentication, which can further restrict attempted attacks, as can a firewall configured to deny SSH connection attempts from all but a whitelisted set of clients.

Perhaps the most universally usable, and in many cases the most effective, means of restricting access to brute force attacks is to simply deny root access via SSH. Yes, I know — you want to be able to log in remotely and perform administrative tasks that require root access — but you also want to ensure that someone who stumbles across your machine and has the right pieces in place (such as using the correct connection port number) cannot directly gain root access to your box with a brute force, password-cracking attack.

You can still allow other accounts to access the machine via SSH, of course. With either sudo or su, you can then gain root access. Since automated attacks are even less able to guess both an unknown user account name and its password (especially if the password is sufficiently complex) — and, in fact, most never bother to try for any account other than root because of this — the security of your system from automated SSH attacks will be greatly increased by taking this simple measure. That is particularly true if you do not allow the general user accounts to use sudo or su to gain root access. You may designate a special administrative account with greatly restricted privileges on the system, but with one privilege that no other non-root accounts have: the ability to perform administrative tasks with root privileges via su or sudo.

However you choose to arrange for administrative access, once you have disallowed direct root access over SSH, it’s a very rare circumstance where you should allow remote root access at all. To disable direct root logins via SSH, edit the ssdh_config file again so that there is a PermitRootLogin line that is uncommented and set to “no”:

PermitRootLogin no

Some operating systems, such as FreeBSD, have this set as a default. Others, such as most Linux distributions, do not. Check out your particular choice of OS to determine its default PermitRootLogin setting before deciding it’s safe enough as-is.

edit: As TR user eldergabriel pointed out in a comment to this article, more information about securing the OpenSSH daemon can be found in the sshd_config manpage. Most Unix-like OSes with OpenSSH installed should have that manpage as well, and you can read it with the command man sshd_config or via whatever Unix manual interface you prefer and have available (such as the xman documentation browser).

Chad PerrinChad Perrin is an IT consultant, developer, and freelance professional writer. He holds both Microsoft and CompTIA certifications and is a graduate of two IT industry trade schools. Read his full bio and profile.

Print/View all Posts Comments on this blog

additional protections george.r.boyce@... | 11/01/07
That's all good advice . . . apotheon | 11/01/07
value and cost of security george.r.boyce@... | 11/02/07
check out this example apotheon | 11/02/07
RE: Protect SSH from brute force password-cracking attacks steven.macfarlane@... | 11/01/07
Had some luck with DenyHosts on Linux. williamjones | 11/01/07
denyhosts: here, here... eldergabriel@... | 11/12/07
re: "doing work as root" apotheon | 11/01/07
Port 1138? Awesome :-) THX-1138 | 11/07/07
You're welcome. apotheon | 11/08/07
Deny/AllowUsers, Deny/AllowGroups... eldergabriel@... | 11/12/07
oh contrare dear sir - most attacks? TG2 | 11/13/07
Total agreement DanLM | 11/13/07
Total agreement DanLM | 11/13/07
Yes, most. apotheon | 11/14/07
Still disagree -- and additionally what install doesn't disallow root? TG2 | 11/15/07
I'm not sure why you don't understand what I'm saying. apotheon | 11/15/07
disagree - not targeted, and attacker needs to know nothing of victim TG2 | 11/16/07
five points, and an off-topic note apotheon | 11/18/07
So then I'll break it down for better understanding TG2 | 11/18/07
Is this some kind of joke? apotheon | 11/19/07
Again? TG2 | 11/20/07
. . . apotheon | 11/20/07
NM..end thread TG2 | 11/21/07
Apotheon is right TechExec2 | 11/15/07
Unfortunately not correct, not a directed attack TG2 | 11/16/07

What do you think?

White Papers, Webcasts, and Downloads

Recent Entries

TR on Twitter

Archives

TechRepublic Blogs



500 Things Every Technology Professional Needs to Know
Did you know Microsoft's RegClean does not work with XP but you can use shareware to clean your registry? Did you know most wireless access points don't have encryption enabled by default? Did you know there are 500 tidbits of information contained in TechRepublic's 500 Things Every Technology Professional Needs to Know that will help you become a successful IT professional.
Buy Now
IT Professional's Guide to Policies and Procedures, Third Ed
Whether you're creating policies for management, training, personnel, support, privacy, Internet/e-mail usage, security, or inventory, you'll meet the needs of your entire enterprise with this one download!
Buy Now

SmartPlanet

Click Here