从 Windows 客户端使用 Kerberos 进行 SSH

从 Windows 客户端使用 Kerberos 进行 SSH

我有一台 Ubuntu 22.04 LTS 机器,我已使用 SSSD 将其加入到我的 Active Directory 中。一切都很好,我可以使用我的 AD 用户登录到 Linux 服务器,用户在登录时会获得 kerberos 票证等。

我想让客户端能够使用 kerberos 通过 SSH 连接到这台机器,这样他们就不需要在登录时输入密码。

在 Ubuntu 服务器上,我编辑了 /etc/ssh/sshd_config 以包含以下内容:

GSSAPIAuthentication yes

并重新启动 sshd 服务。现在,当我在已加入同一 AD 的 Windows 计算机上打开 PowerShell 并输入ssh -K ubuntu-server1.domain.local我收到输入用户名密码的提示域\用户名1 我尝试使用 Putty 也启用 GSSAPI 身份验证,但没有任何运气。

感觉就像我尝试过各种不同的设置sshd_conf和腻子没有任何运气。我还在我的 Windows 机器上安装了 SSH 服务器并启用GSSAPI认证为此,我可以使用以下命令从 Linux 服务器登录到我的 Windows 客户端ssh -K windows-client1.domain.local它让我在没有密码提示的情况下直接登录..

DNS 是正确的,包括反向查找。时间也是正确的。

当将 Linux 机器加入 AD 时,我刚刚运行:

realm join domain.local

我还没有做太多/etc/sssd/sssd.conf不仅仅是一些调整:

[sssd]
domains = domain.local
config_file_version = 2
services = nss, pam, sudo

[domain/domain.local]
default_shell = /bin/bash
krb5_store_password_if_offline = True
cache_credentials = True
krb5_realm = DOMAIN.LOCAL
realmd_tags = manages-system joined-with-adcli
id_provider = ad
fallback_homedir = /home/%d/%u
ad_domain = DOMAIN.local
ad_hostname = ubuntu-server1.domain.local
use_fully_qualified_names = True
ldap_id_mapping = True
access_provider = simple
sudo_provider = ad

dyndns_update = true
dyndns_refresh_interval = 43200
dyndns_update_ptr = true
dyndns_ttl = 3600
simple_allow_groups = [email protected]

[sudo]

/etc/krb5.conf不包含太多:

[libdefaults]
udp_preference_limit = 0
default_realm = DOMAIN.LOCAL

我已经多次验证DNS是正确的。我可以很好地查找所有内容,包括 PTR 记录。

我在 Linux 机器上启动了一个单独的 sshd 服务,以便更轻松地进行故障排除,如下所示:

KRB5_TRACE=/tmp/ssh-krb5trace /sbin/sshd -D -d -p 2222

我在收到密码提示并使用 CTRL+C 取消它后得到了这个:

debug1: sshd version OpenSSH_8.9, OpenSSL 3.0.2 15 Mar 2022
debug1: private host key #0: ssh-rsa SHA256:I0ONIQ8tkt6KIoX12VZI2exO3e9HCiY8qsykdJ3lvK0
debug1: private host key #1: ecdsa-sha2-nistp256 SHA256:Ab/OZTiog2d/tptR8g/xDvdXGWIxU3cas1glKE1i3l4
debug1: private host key #2: ssh-ed25519 SHA256:07VGrICNBYTljMqraC9tx0MxzShBXXaS5dHsQQ2Of3Q
debug1: rexec_argv[0]='/sbin/sshd'
debug1: rexec_argv[1]='-D'
debug1: rexec_argv[2]='-d'
debug1: rexec_argv[3]='-p'
debug1: rexec_argv[4]='2222'
debug1: Set /proc/self/oom_score_adj from 0 to -1000
debug1: Bind to port 2222 on 0.0.0.0.
Server listening on 0.0.0.0 port 2222.
debug1: Bind to port 2222 on ::.
Server listening on :: port 2222.
debug1: Server will not fork when running in debugging mode.
debug1: rexec start in 5 out 5 newsock 5 pipe -1 sock 8
debug1: sshd version OpenSSH_8.9, OpenSSL 3.0.2 15 Mar 2022
debug1: private host key #0: ssh-rsa SHA256:I0ONIQ8tkt6KIoX12VZI2exO3e9HCiY8qsykdJ3lvK0
debug1: private host key #1: ecdsa-sha2-nistp256 SHA256:Ab/OZTiog2d/tptR8g/xDvdXGWIxU3cas1glKE1i3l4
debug1: private host key #2: ssh-ed25519 SHA256:07VGrICNBYTljMqraC9tx0MxzShBXXaS5dHsQQ2Of3Q
debug1: inetd sockets after dupping: 3, 3
Connection from 192.168.1.120 port 49983 on 10.0.0.230 port 2222 rdomain ""
debug1: Local version string SSH-2.0-OpenSSH_8.9p1 Ubuntu-3ubuntu0.4
debug1: Remote protocol version 2.0, remote software version OpenSSH_for_Windows_8.1
debug1: compat_banner: match: OpenSSH_for_Windows_8.1 pat OpenSSH* compat 0x04000000
debug1: permanently_set_uid: 110/65534 [preauth]
debug1: list_hostkey_types: rsa-sha2-512,rsa-sha2-256,ecdsa-sha2-nistp256,ssh-ed25519 [preauth]
debug1: SSH2_MSG_KEXINIT sent [preauth]
debug1: SSH2_MSG_KEXINIT received [preauth]
debug1: kex: algorithm: curve25519-sha256 [preauth]
debug1: kex: host key algorithm: ecdsa-sha2-nistp256 [preauth]
debug1: kex: client->server cipher: [email protected] MAC: <implicit> compression: none [preauth]
debug1: kex: server->client cipher: [email protected] MAC: <implicit> compression: none [preauth]
debug1: expecting SSH2_MSG_KEX_ECDH_INIT [preauth]
debug1: SSH2_MSG_KEX_ECDH_INIT received [preauth]
debug1: rekey out after 134217728 blocks [preauth]
debug1: SSH2_MSG_NEWKEYS sent [preauth]
debug1: Sending SSH2_MSG_EXT_INFO [preauth]
debug1: expecting SSH2_MSG_NEWKEYS [preauth]
debug1: SSH2_MSG_NEWKEYS received [preauth]
debug1: rekey in after 134217728 blocks [preauth]
debug1: KEX done [preauth]
debug1: userauth-request for user domain\\\\username1 service ssh-connection method none [preauth]
debug1: attempt 0 failures 0 [preauth]
debug1: PAM: initializing for "domain\\username1"
debug1: PAM: setting PAM_RHOST to "192.168.1.120"
debug1: PAM: setting PAM_TTY to "ssh"
debug1: userauth-request for user domain\\\\username1 service ssh-connection method publickey [preauth]
debug1: attempt 1 failures 0 [preauth]
debug1: userauth_pubkey: publickey test pkalg rsa-sha2-512 pkblob RSA SHA256:zxEs2+751dYAs84032EwQZxYOqA0js4k0mqI/rfU08w [preauth]
debug1: temporarily_use_uid: 217401201/217400513 (e=0/0)
debug1: trying public key file /home/domain.local/username1/.ssh/authorized_keys
debug1: Could not open authorized keys '/home/domain.local/username1/.ssh/authorized_keys': No such file or directory
debug1: restore_uid: 0/0
debug1: temporarily_use_uid: 217401201/217400513 (e=0/0)
debug1: trying public key file /home/domain.local/username1/.ssh/authorized_keys2
debug1: Could not open authorized keys '/home/domain.local/username1/.ssh/authorized_keys2': No such file or directory
debug1: restore_uid: 0/0
Failed publickey for domain\\username1 from 192.168.1.120 port 49983 ssh2: RSA SHA256:zxEs2+751dYAs84032EwQZxYOqA0js4k0mqI/rfU08w
Connection reset by authenticating user domain\\\\username1 192.168.1.120 port 49983 [preauth]
debug1: do_cleanup [preauth]
debug1: monitor_read_log: child log fd closed
debug1: do_cleanup
debug1: PAM: cleanup
debug1: Killing privsep child 964423
debug1: audit_event: unhandled event 12

我什么也没得到/tmp/ssh-krb5trace除非我使用密码登录,否则它看起来像这样:

[963733] 1700139671.168219: Getting initial credentials for [email protected]
[963733] 1700139671.168222: Sending unauthenticated request
[963733] 1700139671.168223: Sending request (193 bytes) to domain.local
[963733] 1700139671.168224: Sending DNS URI query for _kerberos.domain.local.
[963733] 1700139671.168225: No URI records found
[963733] 1700139671.168226: Sending DNS SRV query for _kerberos._udp.domain.local.
[963733] 1700139671.168227: SRV answer: 0 100 88 "domain-dc02.domain.local."
[963733] 1700139671.168228: SRV answer: 0 100 88 "domain-dc01.domain.local."
[963733] 1700139671.168229: Sending DNS SRV query for _kerberos._tcp.domain.local.
[963733] 1700139671.168230: SRV answer: 0 100 88 "domain-dc01.domain.local."
[963733] 1700139671.168231: SRV answer: 0 100 88 "domain-dc02.domain.local."
[963733] 1700139671.168232: Resolving hostname domain-dc02.domain.local.
[963733] 1700139671.168233: Resolving hostname domain-dc01.domain.local.
[963733] 1700139671.168234: Resolving hostname domain-dc01.domain.local.
[963733] 1700139671.168235: Initiating TCP connection to stream 10.100.1.5:88
[963733] 1700139671.168236: Sending TCP request to stream 10.100.1.5:88
[963733] 1700139671.168237: Received answer (192 bytes) from stream 10.100.1.5:88
[963733] 1700139671.168238: Terminating TCP connection to stream 10.100.1.5:88
[963733] 1700139671.168239: Sending DNS URI query for _kerberos.domain.local.
[963733] 1700139671.168240: No URI records found
[963733] 1700139671.168241: Sending DNS SRV query for _kerberos-master._tcp.domain.local.
[963733] 1700139671.168242: No SRV records found
[963733] 1700139671.168243: Response was not from primary KDC
[963733] 1700139671.168244: Received error from KDC: -1765328359/Additional pre-authentication required
[963733] 1700139671.168247: Preauthenticating using KDC method data
[963733] 1700139671.168248: Processing preauth types: PA-PK-AS-REQ (16), PA-PK-AS-REP_OLD (15), PA-ETYPE-INFO2 (19), PA-ENC-TIMESTAMP (2)
[963733] 1700139671.168249: Selected etype info: etype aes256-cts, salt "domain.LOCALusername1", params ""
[963733] 1700139671.168250: AS key obtained for encrypted timestamp: aes256-cts/66C7
[963733] 1700139671.168252: Encrypted timestamp (for 1700139671.649114): plain 301AA011180F32303233313131363133303131315AA105020309E79A, encrypted 57F8E4BB1AA92F9A66F4E7E6135EE823285830662C1F040754995BF8ED42D9913EE1403B8E7FC92211FD04D313ED3D56F83675F2B5DA4E03
[963733] 1700139671.168253: Preauth module encrypted_timestamp (2) (real) returned: 0/Success
[963733] 1700139671.168254: Produced preauth for next request: PA-ENC-TIMESTAMP (2)
[963733] 1700139671.168255: Sending request (273 bytes) to domain.local
[963733] 1700139671.168256: Sending DNS URI query for _kerberos.domain.local.
[963733] 1700139671.168257: No URI records found
[963733] 1700139671.168258: Sending DNS SRV query for _kerberos._udp.domain.local.
[963733] 1700139671.168259: SRV answer: 0 100 88 "domain-dc01.domain.local."
[963733] 1700139671.168260: SRV answer: 0 100 88 "domain-dc02.domain.local."
[963733] 1700139671.168261: Sending DNS SRV query for _kerberos._tcp.domain.local.
[963733] 1700139671.168262: SRV answer: 0 100 88 "domain-dc02.domain.local."
[963733] 1700139671.168263: SRV answer: 0 100 88 "domain-dc01.domain.local."
[963733] 1700139671.168264: Resolving hostname domain-dc01.domain.local.
[963733] 1700139671.168265: Resolving hostname domain-dc02.domain.local.
[963733] 1700139671.168266: Resolving hostname domain-dc02.domain.local.
[963733] 1700139671.168267: Initiating TCP connection to stream 192.168.1.5:88
[963733] 1700139671.168268: Sending TCP request to stream 192.168.1.5:88
[963733] 1700139671.168269: Received answer (1793 bytes) from stream 192.168.1.5:88
[963733] 1700139671.168270: Terminating TCP connection to stream 192.168.1.5:88
[963733] 1700139671.168271: Sending DNS URI query for _kerberos.domain.local.
[963733] 1700139671.168272: No URI records found
[963733] 1700139671.168273: Sending DNS SRV query for _kerberos-master._tcp.domain.local.
[963733] 1700139671.168274: No SRV records found
[963733] 1700139671.168275: Response was not from primary KDC
[963733] 1700139671.168276: Processing preauth types: PA-ETYPE-INFO2 (19)
[963733] 1700139671.168277: Selected etype info: etype aes256-cts, salt "domain.LOCALusername1", params ""
[963733] 1700139671.168278: Produced preauth for next request: (empty)
[963733] 1700139671.168279: AS key determined by preauth: aes256-cts/66C7
[963733] 1700139671.168280: Decrypted AS reply; session key is: aes256-cts/E1E4
[963733] 1700139671.168281: FAST negotiation: unavailable
[963733] 1700139671.168282: Retrying AS request with primary KDC
[963733] 1700139671.168283: Getting initial credentials for [email protected]
[963733] 1700139671.168285: Sending unauthenticated request
[963733] 1700139671.168286: Sending request (193 bytes) to domain.local (primary)
[963733] 1700139671.168287: Sending DNS URI query for _kerberos.domain.local.
[963733] 1700139671.168288: No URI records found
[963733] 1700139671.168289: Sending DNS SRV query for _kerberos-master._udp.domain.local.
[963733] 1700139671.168290: Sending DNS SRV query for _kerberos-master._tcp.domain.local.
[963733] 1700139671.168291: No SRV records found

我觉得我对 Kerberos 和 SSSD 还不太了解,所以我可能会忽略一些简单的东西。任何有关此的信息都会有帮助!

编辑:我忘记包含 Windows 机器的日志。我强迫 kerberos 与-o PreferredAuthentications=gssapi-with-mic

> ssh -v -K -o PreferredAuthentications=gssapi-with-mic ubuntu-server1.domain.local
OpenSSH_for_Windows_8.1p1, LibreSSL 3.0.2
debug1: Reading configuration data C:\\Users\\username1/.ssh/config
debug1: Connecting to ubuntu-server1.domain.local [10.0.0.230] port 22.
debug1: Connection established.
debug1: identity file C:\\Users\\username1/.ssh/id_rsa type 0
debug1: identity file C:\\Users\\username1/.ssh/id_rsa-cert type -1
debug1: identity file C:\\Users\\username1/.ssh/id_dsa type -1
debug1: identity file C:\\Users\\username1/.ssh/id_dsa-cert type -1
debug1: identity file C:\\Users\\username1/.ssh/id_ecdsa type -1
debug1: identity file C:\\Users\\username1/.ssh/id_ecdsa-cert type -1
debug1: identity file C:\\Users\\username1/.ssh/id_ed25519 type -1
debug1: identity file C:\\Users\\username1/.ssh/id_ed25519-cert type -1
debug1: identity file C:\\Users\\username1/.ssh/id_xmss type -1
debug1: identity file C:\\Users\\username1/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_for_Windows_8.1
debug1: Remote protocol version 2.0, remote software version OpenSSH_8.9p1 Ubuntu-3ubuntu0.4
debug1: match: OpenSSH_8.9p1 Ubuntu-3ubuntu0.4 pat OpenSSH* compat 0x04000000
debug1: Authenticating to ubuntu-server1.domain.local:22 as 'domain\\username1'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: [email protected] MAC: <implicit> compression: none
debug1: kex: client->server cipher: [email protected] MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:Ab/OZTiog2d/tptR8g/xDvdXGWIxU3cas1glKE1i3l4
debug1: Host 'ubuntu-server1.domain.local' is known and matches the ECDSA host key.
debug1: Found key in C:\\Users\\username1/.ssh/known_hosts:8
debug1: rekey out after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey in after 134217728 blocks
debug1: pubkey_prepare: ssh_get_authentication_socket: No such file or directory
debug1: Will attempt key: C:\\Users\\username1/.ssh/id_rsa RSA SHA256:zxEs2+751dYAs84032EwQZxYOqA0js4k0mqI/rfU08w
debug1: Will attempt key: C:\\Users\\username1/.ssh/id_dsa
debug1: Will attempt key: C:\\Users\\username1/.ssh/id_ecdsa
debug1: Will attempt key: C:\\Users\\username1/.ssh/id_ed25519
debug1: Will attempt key: C:\\Users\\username1/.ssh/id_xmss
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,[email protected],ssh-rsa,rsa-sha2-256,rsa-sha2-512,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,[email protected],[email protected]>
debug1: kex_input_ext_info: [email protected] (unrecognised)
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,gssapi-with-mic,password
debug1: Next authentication method: gssapi-with-mic
debug1: GSS_S_FAILURE
debug1: No more authentication methods to try.
domain\\[email protected]: Permission denied (publickey,gssapi-with-mic,password).

所以我得到GSS_S_FAILURE因为某些原因。会调查这个。任何帮助表示赞赏。

编辑2:

所以我走得更远了一点。现在,当我连接到故障排除 SSHD 时,我收到以下信息:

debug1: No credentials were supplied, or the credentials were unavailable or inaccessible
No key table entry found matching host/ubuntu-server1.domain.local@

我不是 Kerberos 专家,但这看起来有点奇怪。如果我查看我的密钥表,我会得到以下信息:

[username1@ubuntu-server1:~]$ sudo ktutil
ktutil:  read_kt /etc/krb5.keytab
ktutil:  l
slot KVNO Principal
---- ---- ---------------------------------------------------------------------
   1    2              [email protected]
   2    2              [email protected]
   3    2              [email protected]
   4    2          host/[email protected]
   5    2          host/[email protected]
   6    2          host/[email protected]
   7    2 host/[email protected]
   8    2 host/[email protected]
   9    2 host/[email protected]
  10    2 RestrictedKrbHost/[email protected]
  11    2 RestrictedKrbHost/[email protected]
  12    2 RestrictedKrbHost/[email protected]
  13    2 RestrictedKrbHost/[email protected]
  14    2 RestrictedKrbHost/[email protected]
  15    2 RestrictedKrbHost/[email protected]

与 host/ubuntu-server1.domain.local@ 不对应,最后缺少 DOMAIN.LOCAL 。所以我猜测某个地方配置错误..但在哪里呢?

相关内容