限制某些 SSH 用户仅进行公钥身份验证的最佳方法(禁用密码身份验证)

cdw*_*son 7 mac ssh configuration mac-osx

我在 Yosemite 上运行 Mac OS X Server.app,并且我为使用默认设置的用户启用了 SSH /etc/sshd_config(默认情况下启用公钥和密码身份验证)。 但是,我需要限制git本地用户只能通过 SSH 访问公钥。

完全公开,Server.app 启用了一些额外的 Kerberos 和 GSSAPI 选项(虽然我不是 100% 确定这些如何影响我下面的问题):

# Kerberos options
KerberosAuthentication yes
KerberosOrLocalPasswd yes
KerberosTicketCleanup yes

# GSSAPI options
GSSAPIAuthentication yes
GSSAPICleanupCredentials yes
GSSAPIStrictAcceptorCheck yes
GSSAPIKeyExchange no
Run Code Online (Sandbox Code Playgroud)

/etc/sshd_config 说如下:

# To disable tunneled clear text passwords both PasswordAuthentication and
# ChallengeResponseAuthentication must be set to "no".
Run Code Online (Sandbox Code Playgroud)

但是,ChallengeResponseAuthenticationmatch 语句中不允许使用,所以我尝试仅禁用密码身份验证:

Match User git
      PasswordAuthentication no
Run Code Online (Sandbox Code Playgroud)

这不起作用——我仍然能够使用用户名/密码登录 git@my.server :(

但是,添加KbdInteractiveAuthentication no似乎可以正常工作:

Match User git
      PasswordAuthentication no
      KbdInteractiveAuthentication no
Run Code Online (Sandbox Code Playgroud)

现在我Permission denied (publickey,gssapi-keyex,gssapi-with-mic)尝试在没有公钥的情况下登录。这似乎表明除了 publickey 之外还有其他方法可以允许git用户登录(即gssapi-keyexgssapi-with-mic

似乎更好的方法是简单地将身份验证方法限制为publickey

Match User git
    AuthenticationMethods publickey
Run Code Online (Sandbox Code Playgroud)

这给出了响应`Permission denied (publickey)。

问题:

  1. ChallengeResponseAuthentication和 和有 KbdInteractiveAuthentication什么区别?为什么 KbdInteractiveAuthentication在 match 语句中允许但不允许 ChallengeResponseAuthentication
  2. 这种AuthenticationMethods publickey方法有任何缺点/安全问题吗?
  3. (如果您能帮助我理解gssapi-keyex/gssapi-with-mic以及它们与启用的 GSSAPI/Kerberos 选项的关系,则奖励)

Pau*_*ane 5

有之间的差异的一个很好的总结ChallengeResponseAuthentication,并KbdInteractiveAuthenticationhttp://blog.tankywoo.com/linux/2013/09/14/ssh-passwordauthentication-vs-challengeresponseauthentication.html -总之是经常询问-最终只是要求密码(但坚持以交互方式提供)。

KbdInteractiveAuthentication并且ChallengeResponseAuthentication是不同的东西。只是ChallengeResponseAuthentication在简单的情况下最终可能会提示输入密码。

ChallengeResponseAuthentication是全局设置,不能在Match子句中指定-sshd_config有关详细信息,请参阅手册页。

AuthenticationMethods publickeygit用户明确指定应该可以正常工作,并且比禁用您不想要的更好(因为列表可能会更改)。

gssapi如果您在Kerberos环境(例如 Active Directory 域)中工作,这些选项就会发挥作用。