I've read how it is possible to disable password authentication on an Ubuntu server. However, is it possible to disable this for remote users only?
I'm afraid that, if I enable this both locally and remotely (as designed), I will ultimately lose the key and lock myself out (over time). If I were able to disable password authentication for remote users only, losing the key wouldn't be so tragic; I could simply go to the LAN and login with a password and create a new key.
From the
sshd_config(5)
manpage:This means that, assuming 10.0.0.0/24 to be your LAN, you can have
PasswordAuthentication
disabled in the main configuration and aMatch
block like this:You can put all remote users into a local (additional) group ex. 'remoteusr' and disallow login with password in 'sshd_config'
An option I've seen used before is to run two instances of sshd reading from separate config files. Your default one listens for normal SSH traffic, configured as securely as you want.
The second instance is your "back door", which listens only on a separate port or separate IP, perhaps with appropriate firewall rules to prevent access from outside the network. It's configured differently; perhaps allowing password auth, perhaps allowing access to accounts that are disallowed in the primary, etc.