Jan 31, 2012
tom

Change the SSH authentication method depending on the IP address

Question

How can I setup my SSH server so that the authentication method depends upon the client IP address?

internal network -> password login enabled
request from WAN -> only passkeys enabled

I would avoid to setup two accounts (internal/external) for each user and rewrite the configuration file accordingly.

Asked by ziu

Answer

Have a look at the man page for sshd_config. If you have a reasonably up-to-date version of OpenSSH you can use Match directives:

Match Address 192.168.0.0/24
  PasswordAuthentication yesMatch Address 10.0.0.0/24
  PasswordAuthentication no

But as ErikA says, just use keyauth anyway and don’t let on that you can do this ;-)

Answered by James O'Gorman

Related posts:

  1. Change SSH authentication method depending on IP
  2. How to set up SSH passwordless key authentication for remote access only, allowing local users to use passwords
  3. Disable ssh password authentication by user
  4. how to disable SSH login with password for some users?
  5. How can roaming user access same domain with varying IP address depending on location?

Leave a comment