如何设置Openssh和Mit kerberos(从Windows到Linux服务器)?

dax*_*x90 5 ssh kerberos mitkerberos

我需要使用 kerberos 票证通过 openssh 从 Windows 连接到 Linux 服务器。我从以下位置获取了 bin 文件: https ://github.com/NoMoreFood/openssh-portable/releases/tag/v7.9-sspi

通过我的公司登录 UI,我使用 MIT Kerberos 获取票证。如果我跑

klist
Run Code Online (Sandbox Code Playgroud)

这是输出

Ticket cache: FILE:C:\Users\Test\....\host.domain.subdomain.local
Default principal: USER@REALM

Valid starting     Expires            Service principal
09/23/19 16:18:53  09/23/19 19:18:53  krbtgt/REALM@REALM
09/23/19 16:18:56  09/23/19 19:18:53  krbtgt/DOMAIN@REALM
09/23/19 16:18:56  09/23/19 19:18:53  host/host.domain.subdomain.local@DOMAIN
Run Code Online (Sandbox Code Playgroud)

使用 Putty 我没有连接问题。所以我尝试使用 openssh 二进制文件:

ssh -Kvvv USER@HOST
Run Code Online (Sandbox Code Playgroud)

配置文件在哪里

Host HOST
    GSSAPIDelegateCredentials yes
    GSSAPIAuthentication yes
Run Code Online (Sandbox Code Playgroud)

我到达服务器,但它询问我密码并且不发送 kerberos 票证

这是日志

OpenSSH_for_Windows_7.9p1, LibreSSL 2.6.4
debug1: Reading configuration data C:\\Users\\Test/.ssh/config
debug1: C:\\Users\\Test/.ssh/config line 7: Applying options for HOST
debug3: Failed to open file:C:/ProgramData/ssh/ssh_config error:2
debug2: resolving HOST port 22
debug2: ssh_connect_direct
debug1: Connecting to HOST [ip] port 22.
debug1: Connection established.
debug3: Failed to open file:C:/Users/Test/.ssh/id_rsa error:2
debug3: Failed to open file:C:/Users/Test/.ssh/id_rsa.pub error:2
debug1: identity file C:\\Users\\Test/.ssh/id_rsa type -1
debug3: Failed to open file:C:/Users/Test/.ssh/id_rsa-cert error:2
debug3: Failed to open file:C:/Users/Test/.ssh/id_rsa-cert.pub error:2
debug1: identity file C:\\Users\\Test/.ssh/id_rsa-cert type -1
debug3: Failed to open file:C:/Users/Test/.ssh/id_dsa error:2
debug3: Failed to open file:C:/Users/Test/.ssh/id_dsa.pub error:2
debug1: identity file C:\\Users\\Test/.ssh/id_dsa type -1
debug3: Failed to open file:C:/Users/Test/.ssh/id_dsa-cert error:2
debug3: Failed to open file:C:/Users/Test/.ssh/id_dsa-cert.pub error:2
debug1: identity file C:\\Users\\Test/.ssh/id_dsa-cert type -1
debug3: Failed to open file:C:/Users/Test/.ssh/id_ecdsa error:2
debug3: Failed to open file:C:/Users/Test/.ssh/id_ecdsa.pub error:2
debug1: identity file C:\\Users\\Test/.ssh/id_ecdsa type -1
debug3: Failed to open file:C:/Users/Test/.ssh/id_ecdsa-cert error:2
debug3: Failed to open file:C:/Users/Test/.ssh/id_ecdsa-cert.pub error:2
debug1: identity file C:\\Users\\Test/.ssh/id_ecdsa-cert type -1
debug3: Failed to open file:C:/Users/Test/.ssh/id_ed25519 error:2
debug3: Failed to open file:C:/Users/Test/.ssh/id_ed25519.pub error:2
debug1: identity file C:\\Users\\Test/.ssh/id_ed25519 type -1
debug3: Failed to open file:C:/Users/Test/.ssh/id_ed25519-cert error:2
debug3: Failed to open file:C:/Users/Test/.ssh/id_ed25519-cert.pub error:2
debug1: identity file C:\\Users\\Test/.ssh/id_ed25519-cert type -1
debug3: Failed to open file:C:/Users/Test/.ssh/id_xmss error:2
debug3: Failed to open file:C:/Users/Test/.ssh/id_xmss.pub error:2
debug1: identity file C:\\Users\\Test/.ssh/id_xmss type -1
debug3: Failed to open file:C:/Users/Test/.ssh/id_xmss-cert error:2
debug3: Failed to open file:C:/Users/Test/.ssh/id_xmss-cert.pub error:2
debug1: identity file C:\\Users\\Test/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_for_Windows_7.9
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.4
debug1: match: OpenSSH_7.4 pat OpenSSH_7.0*,OpenSSH_7.1*,OpenSSH_7.2*,OpenSSH_7.3*,OpenSSH_7.4*,OpenSSH_7.5*,OpenSSH_7.6*,OpenSSH_7.7* compat 0x04000002
debug2: fd 3 setting O_NONBLOCK
debug1: Authenticating to HOST:22 as USER
debug3: hostkeys_foreach: reading file "C:\\Users\\Test/.ssh/known_hosts"
debug3: record_hostkey: found key type ECDSA in file C:\\Users\\Test/.ssh/known_hosts:1
debug3: load_hostkeys: loaded 1 keys from HOST
debug3: Failed to open file:C:/Users/Test/.ssh/known_hosts2 error:2
debug3: Failed to open file:C:/ProgramData/ssh/ssh_known_hosts error:2
debug3: Failed to open file:C:/ProgramData/ssh/ssh_known_hosts2 error:2
debug3: order_hostkeyalgs: prefer hostkeyalgs: [..]
debug3: send packet: type 20
debug1: SSH2_MSG_KEXINIT sent
debug3: receive packet: type 20
debug1: SSH2_MSG_KEXINIT received
debug2: local client KEXINIT proposal
debug2: KEX algorithms: [...]
debug2: host key algorithms: [...]
debug2: ciphers ctos: [...]
debug2: ciphers stoc: [...]
debug2: MACs ctos: [...]
debug2: MACs stoc: [...]
debug2: compression ctos: none
debug2: compression stoc: none
debug2: languages ctos:
debug2: languages stoc:
debug2: first_kex_follows 0
debug2: reserved 0
debug2: peer server KEXINIT proposal
debug2: KEX algorithms: [...]
debug2: host key algorithms: [...]
debug2: ciphers ctos: [...]
debug2: ciphers stoc: [...]
debug2: MACs ctos: [...]
debug2: MACs stoc: [...]
debug2: compression ctos: none,zlib@openssh.com
debug2: compression stoc: none,zlib@openssh.com
debug2: languages ctos:
debug2: languages stoc:
debug2: first_kex_follows 0
debug2: reserved 0
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug3: send packet: type 30
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug3: receive packet: type 31
debug1: Server host key: [...]
debug3: hostkeys_foreach: reading file "C:\\Users\\Test/.ssh/known_hosts"
debug3: record_hostkey: found key type ECDSA in file C:\\Users\\Test/.ssh/known_hosts:1
debug3: load_hostkeys: loaded 1 keys from HOST
debug3: Failed to open file:C:/Users/Test/.ssh/known_hosts2 error:2
debug3: Failed to open file:C:/ProgramData/ssh/ssh_known_hosts error:2
debug3: Failed to open file:C:/ProgramData/ssh/ssh_known_hosts2 error:2
debug3: hostkeys_foreach: reading file "C:\\Users\\Test/.ssh/known_hosts"
debug3: record_hostkey: found key type ECDSA in file C:\\Users\\Test/.ssh/known_hosts:1
debug3: load_hostkeys: loaded 1 keys from IP
debug3: Failed to open file:C:/Users/Test/.ssh/known_hosts2 error:2
debug3: Failed to open file:C:/ProgramData/ssh/ssh_known_hosts error:2
debug3: Failed to open file:C:/ProgramData/ssh/ssh_known_hosts2 error:2
debug1: Host HOST is known and matches the ECDSA host key.
debug1: Found key in C:\\Users\\Test/.ssh/known_hosts:1
debug3: send packet: type 21
debug2: set_newkeys: mode 1
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug3: receive packet: type 21
debug1: SSH2_MSG_NEWKEYS received
debug2: set_newkeys: mode 0
debug1: rekey after 134217728 blocks
debug3: unable to connect to pipe \\\\.\\pipe\\openssh-ssh-agent, error: 2
debug1: pubkey_prepare: ssh_get_authentication_socket: No such file or directory
debug1: Will attempt key: C:\\Users\\Test/.ssh/id_rsa
debug1: Will attempt key: C:\\Users\\Test/.ssh/id_dsa
debug1: Will attempt key: C:\\Users\\Test/.ssh/id_ecdsa
debug1: Will attempt key: C:\\Users\\Test/.ssh/id_ed25519
debug1: Will attempt key: C:\\Users\\Test/.ssh/id_xmss
debug2: pubkey_prepare: done
debug3: send packet: type 5
debug3: receive packet: type 7
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<rsa-sha2-256,rsa-sha2-512>
debug3: receive packet: type 6
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug3: send packet: type 50
debug3: receive packet: type 53
debug3: input_userauth_banner
+-----------------------------------------------------------------+
+-----------------------------------------------------------------+
debug3: receive packet: type 51
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug3: start over, passed a different list publickey,gssapi-keyex,gssapi-with-mic,password
debug3: preferred gssapi-with-mic,publickey,keyboard-interactive,password
debug3: authmethod_lookup gssapi-with-mic
debug3: remaining preferred: publickey,keyboard-interactive,password
debug3: authmethod_is_enabled gssapi-with-mic
debug1: Next authentication method: gssapi-with-mic
debug1: GSS_S_FAILURE
debug2: we did not send a packet, disable method
debug3: authmethod_lookup publickey
debug3: remaining preferred: keyboard-interactive,password
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Trying private key: C:\\Users\\Test/.ssh/id_rsa
debug3: no such identity: C:\\Users\\Test/.ssh/id_rsa: No such file or directory
debug1: Trying private key: C:\\Users\\Test/.ssh/id_dsa
debug3: no such identity: C:\\Users\\Test/.ssh/id_dsa: No such file or directory
debug1: Trying private key: C:\\Users\\Test/.ssh/id_ecdsa
debug3: no such identity: C:\\Users\\Test/.ssh/id_ecdsa: No such file or directory
debug1: Trying private key: C:\\Users\\Test/.ssh/id_ed25519
debug3: no such identity: C:\\Users\\Test/.ssh/id_ed25519: No such file or directory
debug1: Trying private key: C:\\Users\\Test/.ssh/id_xmss
debug3: no such identity: C:\\Users\\Test/.ssh/id_xmss: No such file or directory
debug2: we did not send a packet, disable method
debug3: authmethod_lookup password
debug3: remaining preferred: ,password
debug3: authmethod_is_enabled password
debug1: Next authentication method: password
debug3: failed to open file:C:/dev/tty error:3
debug1: read_passphrase: can't open /dev/tty: No such file or directory
USER@HOST's password:   
Run Code Online (Sandbox Code Playgroud)

编辑: 如果我用 plink 连接一切正常

plink -v hostPuttyAlias
Looking up host HOST for SSH connection
Connecting to ip port 22
We claim version: SSH-2.0-PuTTY_Release_0.72
Remote version: SSH-2.0-OpenSSH_7.4
Using SSH protocol version 2
Doing ECDH key exchange with curve Curve25519 and hash SHA-256 (unaccelerated)
Server also has ecdsa-sha2-nistp256 host key, but we don't know it
Host key fingerprint is:
ssh-ed25519 255 [...]
Initialised AES-256 SDCTR (AES-NI accelerated) outbound encryption
Initialised HMAC-SHA-256 (unaccelerated) outbound MAC algorithm
Initialised AES-256 SDCTR (AES-NI accelerated) inbound encryption
Initialised HMAC-SHA-256 (unaccelerated) inbound MAC algorithm
Using username user.
-- Pre-authentication banner message from server: ----------------------------
Using GSSAPI from GSSAPI64.DLL
Trying gssapi-with-mic...
Attempting GSSAPI authentication
-- End of banner message from server -----------------------------------------
GSSAPI authentication initialised
GSSAPI authentication initialised
GSSAPI authentication loop finished OK
Access granted
Access granted. Press Return to begin session.
Run Code Online (Sandbox Code Playgroud)

小智 3

我添加了一个较晚的答案,因为这个问题仍然是通过 kerberos 连接到 OpenSSH SSH / SFTP / SCP 服务器的最佳 google 结果之一。

\n

简短的答案是尝试ssh -K MyServer,然后完成!当前在 Windows 10/Windows Server 中执行此操作的方法仅需要:

\n
    \n
  • 启用 openssh 客户端工具,或下载它们(如果需要)。
  • \n
  • openssh_for_windows 的最新版本。我这里用的是8.1p1。
  • \n
  • 如果您想要用作远程用户的任何终端与您当前的凭据不同,请运行该终端
  • \n
\n
# Check if the openssh tools are present:\nGet-WindowsCapability -online -name OpenSSH.Client* | Select State\n\nState : NotPresent\n \n# You may or may not need to restart after enabling the client\nAdd-WindowsCapability -Online -Name OpenSSH.Client\n\nOnline        : True\nRestartNeeded : False\n
Run Code Online (Sandbox Code Playgroud)\n
# Make sure you're running as the correct user:\nPS C:\\> whoami\ndomain\\MyUser\n
Run Code Online (Sandbox Code Playgroud)\n

然后就可以直接通过kerberos连接了。这是我的连接的精简调试:

\n
PS C:\\> ssh -Kv my-server.domain.tld\nOpenSSH_for_Windows_8.1p1, LibreSSL 3.0.2\ndebug1: Connecting to my-server.domain.tld [10.0.0.1] port 22.\ndebug1: Connection established.\ndebug1: Authenticating to my-server.domain.tld:22 as 'MyDomain\\\\MyUser'\ndebug1: Next authentication method: gssapi-with-mic\ndebug1: Authentication succeeded (gssapi-with-mic).\n[MyUser@MyServer ~]$ \n
Run Code Online (Sandbox Code Playgroud)\n

瞧\xc3\xa0!

\n

更多细节:

\n

如果您没有该主机的新 kerberos 票证,成功的连接应该会为您创建一张新的 kerberos 票证。请注意,这些被标记为

\n
    \n
  • pre_authent,这意味着您和 SSH 服务器在建立连接时需要能够连接到 AD 域控制器。
  • \n
  • forwardable,它允许将身份验证转发到Server:ID,而无需再次输入密码。
  • \n
\n
# trimmed klist output on windows after connecting successfully:\nPS C:\\> klist\n\n#0>     Client: MyUser @ DOMAIN.TLD\n        Server: krbtgt/DOMAIN.TLD @ DOMAIN.TLD\n        Ticket Flags 0x40e10000 -> forwardable renewable initial pre_authent name_canonicalize\n\n#1>     Client: MyUser @ DOMAIN.TLD\n        Server: host/myserver @ DOMAIN.TLD\n        Ticket Flags 0x40a10000 -> forwardable renewable pre_authent name_canonicalize\n
Run Code Online (Sandbox Code Playgroud)\n

请注意,如果不手动创建新票证,这些票证将不允许您再次跳转,例如:

\n
# MyLaptop -> MyServer -> MySecureServer\n\n# double-hop prompts for password, fails\nPS C:\\MyLaptop\\> ssh -K MyServer\n[myuser@myserver ~]$ ssh -k MySecureServer\nmyuser@mysecureserver's password:\n\n# Generate a new ticket manually, and success:\nPS C:\\MyLaptop\\> ssh -K MyServer\n[myuser@myserver ~]$ kinit\nPassword for myuser@DOMAIN.TLD:\n[myuser@myserver ~]$ ssh -k MySecureServer\n[myuser@mysecureserver ~]$\n
Run Code Online (Sandbox Code Playgroud)\n

同样的规则适用于 PS 会话。

\n