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

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

当我尝试使用 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

如果我强制使用密码(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 [email protected] 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.

服务器正在使用 Active Directory 来存储用户信息,因此我认为这与此有关,但我过去曾在使用 Linux 的 AD 环境中工作过,并没有遇到过这个问题。

答案1

由于不知道机器的具体设置细节,我只能为您提供一个假设。Microsoft Active Directory 建立在 LDAP 上,用于存储用户/目录信息,并建立在 Kerberos5 上,用于身份验证/加密。

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

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

我熟悉使用 pam_krb5 和 libnss-ldapd 来处理这种情况;我不熟悉其他的。如果我的猜测是正确的,一旦你进入 shell,输入“klist -v”来查看是否已经向你发出了票证。

希望这可以帮助。

相关内容