Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

As a first line of defense against brute-force attacks, I've restricted SSH login attempts with TCP wrappers (denying access by default, and maintaining an IP whitelist in /etc/hosts.allow).

However, I sometimes need to access my server from an IP address that's not in the whitelist (and my system ends up blocking my own attempts).

Is it possible to permit SSH keyed logins for all IP addresses, but prohibit password-only logins from IP's not in a given whitelist? I know I can configure SSH to only allowed keyed logins, but I'd like to keep the ability to log in with a password on a range of IP addresses.

share|improve this question
up vote 5 down vote accepted
PasswordAuthentication no

Match Address
    PasswordAuthentication yes

Match Address 2001:470:1f0b:915::/64
    PasswordAuthentication yes

I also set different banner files using Banner to make it clear when password logins are accepted.

share|improve this answer
This is perfect, thank you. To future viewers, just to be clear, this belongs in sshd_config. – David Cain May 12 '13 at 17:48
And what if I do not have an sshd_config? I'm using fail2ban but want to set it up for whitelisting. Guess I ought to make a new question – Jonathan Aug 22 '15 at 20:39
@Jonathan: I'm quite sure you have a sshd_config if you use OpenSSH. And yeah, if you're asking about fail2ban, it has absolutely nothing to do with this question. – grawity Aug 22 '15 at 21:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .