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 5 down vote accepted
PasswordAuthentication no

Match Address 192.168.1.0/24
    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
1  
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 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 at 21:36

Your Answer

 
discard

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.