Cygwin Openssh 密钥认证在 Windows 环境中不起作用

Cygwin Openssh 密钥认证在 Windows 环境中不起作用

我用齐奏在 Windows 10 机器上将我的文件备份到运行 CentOS 的远程服务器。我使用 OpenSSH 和 Cygwin 中的公钥无需密码即可连接到远程机器。直到最近我才遇到任何问题。

如果我使用 Cygwin shell 连接到远程计算机,ssh user@remoteaddress则不会出现任何问题,并且密钥可以正常工作。如果我在 Windows 命令提示符中尝试完全相同的命令,则连接会要求我输入密码。

这一切都是在我修改 Cygwin 安装后开始的。然而,我尝试重新安装 Cygwin 并生成新密钥,但结果相同。

我发现的所有关于此主题的帖子都建议检查服务器和本地计算机上 .ssh 目录的文件权限。然而,这并不能解释为什么它在 Cygwin 中可以工作,但在 Windows 中却不行,而且服务器上没有任何变化。

我已将 Cygwin 正确添加到 Windows 环境路径中,并ssh在命令提示符中被识别。感觉 OpenSSH 或 Cygwin 已更新,并且更新破坏了与 Windows 的集成。

我不是一名程序员,所以这超出了我目前的能力。

以下是来自命令提示符的日志,接下来是来自 Cygwin shell 的日志:

Microsoft Windows [Version 10.0.10586]
(c) 2015 Microsoft Corporation. All rights reserved.

C:\Users\myname>ssh -vvv [email protected]
OpenSSH_5.4p1, OpenSSL 1.0.0 29 Mar 2010
debug1: Reading configuration data /etc/ssh/ssh_config
debug2: ssh_connect: needpriv 0
debug1: Connecting to myname.net [xx.xx.xxx.xxx] port 22.
debug1: Connection established.
debug1: identity file /.ssh/id_rsa type -1
debug1: identity file /.ssh/id_rsa-cert type -1
debug1: identity file /.ssh/id_dsa type -1
debug1: identity file /.ssh/id_dsa-cert type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.3
debug1: match: OpenSSH_5.3 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.4
debug2: fd 3 setting O_NONBLOCK
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug2: kex_parse_kexinit: diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
debug2: kex_parse_kexinit: [email protected],[email protected],ssh-rsa,ssh-dss
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,[email protected]
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,[email protected]
debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,[email protected],hmac-ripemd160,[email protected],hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,[email protected],hmac-ripemd160,[email protected],hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: none,[email protected],zlib
debug2: kex_parse_kexinit: none,[email protected],zlib
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit: first_kex_follows 0
debug2: kex_parse_kexinit: reserved 0
debug2: kex_parse_kexinit: diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
debug2: kex_parse_kexinit: ssh-rsa,ssh-dss
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,[email protected]
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,[email protected]
debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,[email protected],hmac-sha2-256,hmac-sha2-512,hmac-ripemd160,[email protected],hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,[email protected],hmac-sha2-256,hmac-sha2-512,hmac-ripemd160,[email protected],hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: none,[email protected]
debug2: kex_parse_kexinit: none,[email protected]
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit: first_kex_follows 0
debug2: kex_parse_kexinit: reserved 0
debug2: mac_setup: found hmac-md5
debug1: kex: server->client aes128-ctr hmac-md5 none
debug2: mac_setup: found hmac-md5
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug2: dh_gen_key: priv key bits set: 123/256
debug2: bits set: 521/1024
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug3: check_host_in_hostfile: host myname.net filename /.ssh/known_hosts
debug3: check_host_in_hostfile: host myname.net filename /.ssh/known_hosts
debug3: check_host_in_hostfile: match line 2
debug3: check_host_in_hostfile: host xx.xx.xxx.xxx filename /.ssh/known_hosts
debug3: check_host_in_hostfile: host xx.xx.xxx.xxx filename /.ssh/known_hosts
debug3: check_host_in_hostfile: match line 1
debug1: Host 'myname.net' is known and matches the RSA host key.
debug1: Found key in /.ssh/known_hosts:2
debug2: bits set: 486/1024
debug1: ssh_rsa_verify: signature correct
debug2: kex_derive_keys
debug2: set_newkeys: mode 1
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug2: set_newkeys: mode 0
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug2: key: /.ssh/id_rsa (0x0)
debug2: key: /.ssh/id_dsa (0x0)
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 publickey,keyboard-interactive,password
debug3: authmethod_lookup publickey
debug3: remaining preferred: keyboard-interactive,password
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Trying private key: /.ssh/id_rsa
debug3: no such identity: /.ssh/id_rsa
debug1: Trying private key: /.ssh/id_dsa
debug3: no such identity: /.ssh/id_dsa
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
[email protected]'s password:

...从 Cygwin shell 来看:

myname@Windoze ~
$ ssh -vvv [email protected]
OpenSSH_7.1p1, OpenSSL 1.0.2e 3 Dec 2015
debug1: Reading configuration data /etc/ssh_config
debug2: ssh_connect: needpriv 0
debug1: Connecting to myname.net [xx.xx.xxx.xxx] port 22.
debug1: Connection established.
debug1: identity file /home/myname/.ssh/id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file /home/myname/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/myname/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/myname/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/myname/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/myname/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/myname/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/myname/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.3
debug1: match: OpenSSH_5.3 pat OpenSSH_5* compat 0x0c000000
debug2: fd 3 setting O_NONBLOCK
debug1: Authenticating to myname.net:22 as 'myname'
debug3: hostkeys_foreach: reading file "/home/myname/.ssh/known_hosts"
debug3: record_hostkey: found key type RSA in file /home/myname/.ssh/know                                                                        n_hosts:1
debug3: load_hostkeys: loaded 1 keys from myname.net
debug3: order_hostkeyalgs: prefer hostkeyalgs: [email protected],ssh-                                                                        rsa
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug2: kex_parse_kexinit: [email protected],ecdh-sha2-nistp256,ecdh-                                                                        sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hel                                                                        lman-group-exchange-sha1,diffie-hellman-group14-sha1
debug2: kex_parse_kexinit: [email protected],ssh-rsa,ecdsa-sha2-nistp                                                                        [email protected],[email protected],ecdsa-sha2-nis                                                                        [email protected],[email protected],ecdsa-sha2-nistp256,                                                                        ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,ssh-ed25519
debug2: kex_parse_kexinit: [email protected],aes128-ctr,aes192-ctr,a                                                                        es256-ctr,[email protected],[email protected],arcfour256,arcfour128,ae                                                                        s128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndae                                                                        [email protected]
debug2: kex_parse_kexinit: [email protected],aes128-ctr,aes192-ctr,a                                                                        es256-ctr,[email protected],[email protected],arcfour256,arcfour128,ae                                                                        s128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndae                                                                        [email protected]
debug2: kex_parse_kexinit: [email protected],[email protected],hmac                                                                        [email protected],[email protected],[email protected]                                                                        m,[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-sha1                                                                        ,[email protected],[email protected],hmac-sha1-96-etm@openss                                                                        h.com,[email protected],hmac-md5,hmac-ripemd160,hmac-ripemd160@openssh                                                                        .com,hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: [email protected],[email protected],hmac                                                                        [email protected],[email protected],[email protected]                                                                        m,[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-sha1                                                                        ,[email protected],[email protected],hmac-sha1-96-etm@openss                                                                        h.com,[email protected],hmac-md5,hmac-ripemd160,hmac-ripemd160@openssh                                                                        .com,hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: none,[email protected],zlib
debug2: kex_parse_kexinit: none,[email protected],zlib
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit: first_kex_follows 0
debug2: kex_parse_kexinit: reserved 0
debug2: kex_parse_kexinit: diffie-hellman-group-exchange-sha256,diffie-hellman-g                                                                        roup-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
debug2: kex_parse_kexinit: ssh-rsa,ssh-dss
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour12                                                                        8,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rij                                                                        [email protected]
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour12                                                                        8,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rij                                                                        [email protected]
debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,[email protected],hmac-sha2-256,                                                                        hmac-sha2-512,hmac-ripemd160,[email protected],hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,[email protected],hmac-sha2-256,                                                                        hmac-sha2-512,hmac-ripemd160,[email protected],hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: none,[email protected]
debug2: kex_parse_kexinit: none,[email protected]
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit: first_kex_follows 0
debug2: kex_parse_kexinit: reserved 0
debug1: kex: server->client aes128-ctr [email protected] none
debug1: kex: client->server aes128-ctr [email protected] none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<3072<8192) sent
debug1: got SSH2_MSG_KEX_DH_GEX_GROUP
debug2: bits set: 1579/3072
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: got SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Server host key: ssh-rsa SHA256:1vQHO4ohl/PU9lJtFh8OVhQv0vdILmzJ4/AXdYt6                                                                        208
debug3: hostkeys_foreach: reading file "/home/myname/.ssh/known_hosts"
debug3: record_hostkey: found key type RSA in file /home/myname/.ssh/know                                                                        n_hosts:1
debug3: load_hostkeys: loaded 1 keys from myname.net
debug3: hostkeys_foreach: reading file "/home/myname/.ssh/known_hosts"
debug3: record_hostkey: found key type RSA in file /home/myname/.ssh/know                                                                        n_hosts:1
debug3: load_hostkeys: loaded 1 keys from xx.xx.xxx.xxx
debug1: Host 'myname.net' is known and matches the RSA host key.
debug1: Found key in /home/myname/.ssh/known_hosts:1
debug2: bits set: 1524/3072
debug2: set_newkeys: mode 1
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug2: set_newkeys: mode 0
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug2: key: /home/myname/.ssh/id_rsa (0x60006bcf0),
debug2: key: /home/myname/.ssh/id_dsa (0x0),
debug2: key: /home/myname/.ssh/id_ecdsa (0x0),
debug2: key: /home/myname/.ssh/id_ed25519 (0x0),
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mi                                                                        c,password
debug3: start over, passed a different list publickey,gssapi-keyex,gssapi-with-m                                                                        ic,password
debug3: preferred publickey,keyboard-interactive,password

debug3: authmethod_lookup publickey
debug3: remaining preferred: keyboard-interactive,password
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/myname/.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: fp SHA256:bBS6l5Dl4OBi2MHpBjSxJmRHXg6Q5g3+PMKvHKNm                                                                        CZM
debug3: sign_and_send_pubkey: RSA SHA256:bBS6l5Dl4OBi2MHpBjSxJmRHXg6Q5g3+PMKvHKN                                                                        mCZM
debug1: Authentication succeeded (publickey).
Authenticated to myname.net ([xx.xx.xxx.xxx]:22).
debug1: channel 0: new [client-session]
debug3: ssh_session2_open: channel_new: 0
debug2: channel 0: send open
debug1: Requesting [email protected]
debug1: Entering interactive session.
debug2: callback start
debug2: fd 3 setting TCP_NODELAY
debug3: ssh_packet_set_tos: set IP_TOS 0x10
debug2: client_session2_setup: id 0
debug2: channel 0: request pty-req confirm 1
debug2: channel 0: request shell confirm 1
debug2: callback done
debug2: channel 0: open confirm rwindow 0 rmax 32768
debug2: channel_input_status_confirm: type 99 id 0
debug2: PTY allocation request accepted on channel 0
debug2: channel 0: rcvd adjust 2097152
debug2: channel_input_status_confirm: type 99 id 0
debug2: shell request accepted on channel 0
Last login: Sun Dec 20 08:34:02 2015 from ebradford.plus.com
[myname@mynameserver ~]$ debug2: client_check_window_change: changed
debug2: channel 0: request window-change confirm 0
[myname@mynameserver ~]$ ^C

答案1

MS Shell 的 SSH 甚至与 Cygwin 的 SSH 版本不同:

OpenSSH_5.4p1, OpenSSL 1.0.0 29 Mar 2010 (MS)
OpenSSH_7.1p1, OpenSSL 1.0.2e 3 Dec 2015 (cygwin)

您会看到 Cygwin 之间的明显区别:

debug1: identity file /home/myname/.ssh/id_rsa type 1

和 MS:

debug1: identity file /.ssh/id_rsa type -1

MS 版本正在某些无意义的路径中搜索密钥对,但未找到。您可能需要从 Windows shell 中尝试,如下所示:

$ ssh -i /path/to/your/id_rsa [email protected]

相关内容