I configured sshd_config
on two machines A and B in the same way such that connection is possible in local network with password :
Match address 10.0.0.0/8,172.16.0.0/12,192.168.0.0/16
PasswordAuthentication yes
Both machines have only private IPv4, are in a different LAN and behind a different router with a different public IPv4 and can be connected with the public IP of their router (forwarding port from outside to LAN private IP).
Of course if I ssh a machine to itself or to another machine in the same LAN by using their local (IPv4) address, ssh asks for password, as intended. Now see what happens when connecting machines over their router's public IPv4. When
- sshing from A to A by using A's public IP : password is asked
sshing from B to B by using B's public IP :
permission denied (publickey)
sshing from B to A, or from B to A :
permission denied (publickey)
Obviously, in the first case (inside LAN A) sshd matches the client's local network address though it is sshing through public IP, while in second case (inside LAN B), it is not matched . What could be the cause of this difference ?
NOTE: Using Match host localhost
instead of previous one, leads to permission denied in first case (and for other cases of course), because A sshing to itself through router public IP is seen from A itself as having a private LAN IP, not as localhost or public IP.