为什么我每天必须用我的密码登录 ssh 一次?

Cha*_*ens 2 ssh active-directory ssh-keys

当我尝试使用 ssh-agent 中保存的加密密钥 ssh 时,我得到以下信息(使用ssh -vvv):

debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/cowens/.ssh/id_rsa
debug3: send_pubkey_test
debug2: we sent a publickey packet, wait for reply
debug1: Server accepts key: pkalg ssh-rsa blen 279
debug2: input_userauth_pk_ok: BLAH
debug3: sign_and_send_pubkey: RSA BLAH
debug3: input_userauth_banner
Access denied
Access denied
Connection closed by BLAH
Run Code Online (Sandbox Code Playgroud)

如果我强制它使用密码 ( ssh -o PreferredAuthentications=keyboard-interactive -o PubkeyAuthentication=no),我可以登录,然后在我断开连接后(所以它不是 ControlMaster 的事情),我可以使用密钥 ssh 没有问题:

debug1: Offering RSA public key: /home/cowens/.ssh/id_rsa
debug3: send_pubkey_test
debug2: we sent a publickey packet, wait for reply
debug1: Server accepts key: pkalg ssh-rsa blen 279
debug2: input_userauth_pk_ok: BLAH
debug3: sign_and_send_pubkey: BLAH
debug1: Authentication succeeded (publickey).
Authenticated to BLAH ([BLAH]:22).
debug1: channel 0: new [client-session]
debug3: ssh_session2_open: channel_new: 0
debug2: channel 0: send open
debug1: Entering interactive session.
debug2: callback start
debug1: Requesting authentication agent forwarding.
debug2: channel 0: request auth-agent-req@openssh.com confirm 0
debug2: fd 3 setting TCP_NODELAY
debug3: packet_set_tos: set IP_TOS 0x10
debug2: client_session2_setup: id 0
debug2: channel 0: request pty-req confirm 1
debug1: Sending environment.
Run Code Online (Sandbox Code Playgroud)

服务器正在使用 Active Directory 来存储用户信息,所以我认为它与此有关,但我曾在过去将 AD 与 Linux 一起使用的环境中工作过,但没有出现此问题。

eth*_*ish 5

在不知道机器是如何设置的具体细节的情况下,我只能提供一个假设。Microsoft Active Directory 建立在用于用户/目录信息的 LDAP 和用于身份验证/加密的 Kerberos5 之上。

所以,这里是它的核心。当您向 Kerberos 系统进行身份验证时,您将获得一张票证。例如,此票证是操作系统代表您用来在网络上识别您的加密凭据。这些票据通常具有有限的默认生命周期。在这种情况下,我的猜测是大约 10 个小时。

您的 ssh 密钥对将不起作用,因为该服务器上的某些组件被配置为需要您的票证,而获得 kerberos 票证需要您的密码。一旦它被发给你(在那台机器上),它就可以用于任何依赖于它的配置组件。一旦过期,您需要进行身份验证才能获得新的。

我熟悉在这种情况下使用 pam_krb5 和 libnss-ldapd;我不熟悉其他人。如果我的猜测是正确的,那么在您进入 shell 后,输入“klist -v”以查看您是否已获得票证。

希望这可以帮助。