限制从公共网络使用公钥进行 SSH 登录,但允许从内部网络使用密码进行登录

限制从公共网络使用公钥进行 SSH 登录,但允许从内部网络使用密码进行登录

假设用户 A 被允许从公共网络以及私有网络通过 SSH 登录到服务器。

是否有任何选项可以限制对私有网络的密码登录,同时对世界其他地方强制执行公钥认证?

我目前的配置

AllowUsers [email protected] [email protected] usera

如何允许 usera 从[电子邮件保护]/24 使用公钥或密码,并强制来自任何其他网络的用户使用公钥登录?

是否有类似以下操作的方法?确切的符号语法是什么?

# no password login from the public
PasswordAuthentication no
ChallengeResponseAuthentication no

# allow password login from private network
Match Users [email protected]/24 [email protected]/24
   PasswordAuthentication yes

谢谢您的启发。

PS:这样设置的原因是为了在其他方法失败时作为最后的手段,在内部网络内启用密码登录。

答案1

您的配置很接近。我认为您想要的是

PubkeyAuthentication yes
PasswordAuthentication yes

AuthenticationMethods publickey

Match Address 10.0.0.0/24
AuthenticationMethods publickey password

您可以在 中找到详细信息man sshd_config

相关内容