[openssh] deny password login unless attempt is from local the network
This is not an Arch Linux question.
I have an Arch server which I can access from outside the local network using ssh. I like to reject password based ssh-attempts from outside the local network. Can this be done?
About this post
- Posted
- Archived
- Score
- 0 · 100% up
- Kind
- Text
- ID
- dnwm01
9 comments
Are you trying to allow key based access from outside of the LAN and use passwords inside? I would just use ssh-keygen to generate keys and disallow passwords altogether. Otherwise you could just block the port in your router or firewall
I like to have only keybased ssh access from outside the lan. From the inside I don't mind if it is keybased or password based.
Check the "match" option in the sshd config. This can do what you want.
In that case, you can do this with the match directive in the sshd.conf
Great! I already found a tutorial describing what I need to pretty much in the first example: https://raymii.org/s/tutorials/Limit_access_to_openssh_features_with_the_Match_keyword.html
So, I attempted to access the ssh server from outside my lan today. This failed :( The server is listening on a custom port. The laptop I use can access the server from the lan with ecsda key (port 22) But from the outside I got:
"ECSDA host key for ip address " xx" not in list of known hosts"
Is there a config option to make host key checking less strict? I mean, when travelling I have no control over the ip address I am assigned. Or is it the (external) ip address of the router that is not in the list? That ip address changes less frequently, I guess. But I have no control over it ... how to get around this?
I'm not am expert, but I believe the IP is part of the fingerprint to avoid man-in-the-middle attacks. I believe that you can remove the key of a known host using ssh-keygen -R IP (or similar, don't really remember the syntax). I don't know if there's a way to disable it. Does it not just ask if you want to proceed anyway?
Match keyword.
I would advise against developing a system that assumes everything on the LAN is secure/trustworthy and stick with the less complex and proveably secure setup using only key-based auth.
Consider doing some form of 2fa for the password login. U2f, fido2, otp pad or similar. This can actually be better than using keys from external machines if you are working on less than trusted devices. Accessing your private key from some random device might not be the best idea after all.