Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

1 Answer 1

up vote 4 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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.