Recent versions of ufw (in Ubuntu, and Debian 6) have rate limiting features.
Code:
sudo ufw limit ssh
It even works for rating limiting smtp or pop/imap logins, which are the new attack vector of brute forcing. (Or port 80, or whatever you want.)
Code:
stmiller@li166-66:~$ sudo ufw status
[sudo] password for stmiller:
Status: active
To Action From
-- ------ ----
22 LIMIT Anywhere
80 ALLOW Anywhere
443 ALLOW Anywhere
993 LIMIT Anywhere
465 LIMIT Anywhere
25 LIMIT Anywhere
By default this will deny connections of an IP if 6 or more logins are attempted in the last 30 seconds. Though you can customize as desired.