Why is SSH key authentication better than password authentication?

If your SSH service allows password based authentication, then your Internet connected SSH server will be hammered day and night by bot-nets trying to guess user-names and passwords. The bot net needs no information, it can just try popular names and popular passwords. There's an awful lot of people named john with a password of qwerty123. Apart from anything else this clogs your logs.

If your SSH service only allows public-key authentication, an attacker needs a copy of a private key corresponding to a public key stored on the server. They can't just make random attacks, they have to have prior knowledge of your users and have to be able to steal a private key from the PC of an authorized user of your SSH server.

The fact that private keys are often protected by a long pass-phrase is of secondary significance.

Update:

As comments point out, and as I have experienced, moving your SSH service from port 22 to a high numbered port makes a dramatic difference in the number of unauthorized login attempts appearing in your logs. This is worth doing but I do regard it as a form of security by obscurity (a false sense of security) - sooner or later bot-nets will implement slow stealthy port-scanning or you will be deliberately targeted. Better to be prepared.

I always use a long pass-phrase to protect my private key, I guess this is of particular importance on mobile devices that could more easily be lost or stolen.

Also, http://xkcd.com/538/

Security


The logic is that there are a lot more combinations of SSH keys than passwords so it is a lot harder to guess. Using SSH keys also allows you to disable password authentication meaning that most of the automated attacks going round the internet will be useless.

With regard to physical security there's no difference between saving a password and having an unencrypted SSH key on your device if it gets lost or stolen. The only advantage you'd have is that no one has your password and you could theoretically make sure that all devices have different SSH certificates so you can just disable the one for your phone.

I believe it's also possible to password protect SSH keys.


Passwords can also be compromised by your keyboard being monitored "over-your-shoulder". In addition, using similar passwords in many places is a weakness, especially if the password is sometimes used on a less-secure computer with potential keyloggers.

You're right that an unencrypted key can be read off the hard disk if the computer is stolen - so encrypt it with a password.

If your computer is compromised by malware, you're stuffed regardless.. - someone can get the encrypted key and keylog your password.