【问题标题】:Cygwin ssh: lost connection after accessing remote host with id_rsa, id_rsa.pub keysCygwin ssh:使用 id_rsa、id_rsa.pub 键访问远程主机后失去连接
【发布时间】:2017-08-08 23:17:01
【问题描述】:

我的目标是以编程方式将文件从远程服务器复制到本地计算机。使用 Cygwin(服务器)和计算机 Cygwin 64 运行 Windows。

在我创建 rsa 或 dsa 密钥之前,我可以通过输入密码来复制文件

但在创建这些文件后,出现“远程主机关闭连接。丢失连接”错误

我授予以下权限:“chmod 600 .ssh/id_rsa”(在本地计算机上)和 chmod 600“.ssh/authorized_keys2”。有什么问题谁能解答我?

    $ ssh login@hiddenhost
    Connection to hiddenhost closed by remote host.
    Connection to hiddenhost closed.

    PC003370+procserver@ATMPROCSERVER ~
    $ ssh -v login@hiddenhost
    OpenSSH_7.2p2, OpenSSL 1.0.2g  1 Mar 2016
    debug1: Reading configuration data /etc/ssh_config
    debug1: Connecting to hiddenhost [hiddenhost] port 22.
    debug1: Connection established.
    debug1: identity file /home/procserver/.ssh/id_rsa type 1
    debug1: key_load_public: No such file or directory
    debug1: identity file /home/procserver/.ssh/id_rsa-cert type -1
    debug1: key_load_public: No such file or directory
    debug1: identity file /home/procserver/.ssh/id_dsa type -1
    debug1: key_load_public: No such file or directory
    debug1: identity file /home/procserver/.ssh/id_dsa-cert type -1
    debug1: key_load_public: No such file or directory
    debug1: identity file /home/procserver/.ssh/id_ecdsa type -1
    debug1: key_load_public: No such file or directory
    debug1: identity file /home/procserver/.ssh/id_ecdsa-cert type -1
    debug1: key_load_public: No such file or directory
    debug1: identity file /home/procserver/.ssh/id_ed25519 type -1
    debug1: key_load_public: No such file or directory
    debug1: identity file /home/procserver/.ssh/id_ed25519-cert type -1
    debug1: Enabling compatibility mode for protocol 2.0
    debug1: Local version string SSH-2.0-OpenSSH_7.2
    debug1: Remote protocol version 2.0, remote software version OpenSSH_7.1
    debug1: match: OpenSSH_7.1 pat OpenSSH* compat 0x04000000
    debug1: Authenticating to hiddenhost:22 as 'login'
    debug1: SSH2_MSG_KEXINIT sent
    debug1: SSH2_MSG_KEXINIT received
    debug1: kex: algorithm: curve25519-sha256@libssh.org
    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
    debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
    debug1: Server host key: ecdsa-sha2-nistp256 SHA256:TS6tXfpxXyW/KeIWFnvxCsmEhHy8
    8NyoBA3DdOHzjFw
    debug1: Host 'hiddenhost' is known and matches the ECDSA host key.
    debug1: Found key in /home/procserver/.ssh/known_hosts:1
    debug1: rekey after 134217728 blocks
    debug1: SSH2_MSG_NEWKEYS sent
    debug1: expecting SSH2_MSG_NEWKEYS
    debug1: rekey after 134217728 blocks
    debug1: SSH2_MSG_NEWKEYS received
    debug1: SSH2_MSG_SERVICE_ACCEPT received
    debug1: Authentications that can continue: publickey,password,keyboard-interacti
    ve
    debug1: Next authentication method: publickey
    debug1: Offering RSA public key: /home/procserver/.ssh/id_rsa
    debug1: Authentication succeeded (publickey).
    Authenticated to hiddenhost ([hiddenhost]:22).
    debug1: channel 0: new [client-session]
    debug1: Requesting no-more-sessions@openssh.com
    debug1: Entering interactive session.
    debug1: pledge: network
    debug1: channel 0: free: client-session, nchannels 1
    Connection to hiddenhost closed by remote host.
    Connection to hiddenhost closed.
    Transferred: sent 1944, received 1312 bytes, in 0.0 seconds
    Bytes per second: sent 647995.5, received 437330.3
    debug1: Exit status -1

    PC003370+procserver@ATMPROCSERVER ~
    $

【问题讨论】:

    标签: ssh connection cygwin scp


    【解决方案1】:

    万岁!!!!

    我们找到了解决方案。

    所有原因都在于拥有 /var/empty/ 文件夹。我们尝试在调试模式下启动服务器...然后发现这篇文章:

    " 如果您正在调试 SSH 连接,您可能需要手动运行 sshd(而不是作为服务)并启用调试输出。这样做可以让您准确跟踪无法建立连接的原因。但是,如果您尝试手动运行 sshd,您可能会收到以下消息。

    % cygrunsrv.exe --stop sshd

    % /usr/sbin/sshd.exe -D

    无法加载主机密钥:/etc/ssh_host_ecdsa_key /var/empty 必须由 root 拥有,而不是组或全局可写。

    要解决此问题,请将启动 sshd 服务的用户设为 /var/empty 的所有者。

    % ls -ld /var/empty

    drwxr-xr-x+ 1 cyg_server root 0 2010 年 5 月 7 日为空

    % chown /var/empty

    现在,重新启动 sshd。

    % /usr/sbin/sshd.exe -D

    当您完成调试并准备好再次将 sshd 作为服务运行时,将 /var/empty 的所有者更改为 cyg_server。

    % chown cyg_server /var/empty

    % cygrunsrv.exe --start sshd

    注意:您必须具有管理员权限才能运行 "

    【讨论】:

      【解决方案2】:

      我也遇到了同样的问题。根本原因是目录 /var/empty 不是正确的所有者,所以我这样做了: chown $uid.$gid /var/empty 问题已解决。

      【讨论】:

      • 顺便说一句,你可以通过命令“id”找到你自己的$uid和$gid。祝你好运。
      【解决方案3】:

      这就是为我解决问题的方法。

      1. 使用以下命令在调试模式下运行 sshd

        /usr/sbin/sshd.exe -D -dd

      这给了我以下警告

      > $ /usr/sbin/sshd.exe -D -dd debug2: load_server_config: filename
      > /etc/sshd_config debug2: load_server_config: done config len = 285
      > debug2: parse_server_config: config /etc/sshd_config len 285 debug1:
      > sshd version OpenSSH_7.5, OpenSSL 1.0.2k  26 Jan 2017
      > @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @        
      > WARNING: UNPROTECTED PRIVATE KEY FILE!          @
      > @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
      > Permissions 0770 for '/etc/ssh_host_rsa_key' are too open. It is
      > required that your private key files are NOT accessible by others.
      > This private key will be ignored. key_load_private: bad permissions
      > Could not load host key: /etc/ssh_host_rsa_key
      > @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @        
      > WARNING: UNPROTECTED PRIVATE KEY FILE!          @
      > @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
      > Permissions 0770 for '/etc/ssh_host_dsa_key' are too open. It is
      > required that your private key files are NOT accessible by others.
      > This private key will be ignored. key_load_private: bad permissions
      > Could not load host key: /etc/ssh_host_dsa_key
      > @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @        
      > WARNING: UNPROTECTED PRIVATE KEY FILE!          @
      > @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
      > Permissions 0770 for '/etc/ssh_host_ecdsa_key' are too open. It is
      > required that your private key files are NOT accessible by others.
      > This private key will be ignored. key_load_private: bad permissions
      > Could not load host key: /etc/ssh_host_ecdsa_key
      > @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @        
      > WARNING: UNPROTECTED PRIVATE KEY FILE!          @
      > @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
      > Permissions 0770 for '/etc/ssh_host_ed25519_key' are too open. It is
      > required that your private key files are NOT accessible by others.
      > This private key will be ignored. key_load_private: bad permissions
      > Could not load host key: /etc/ssh_host_ed25519_key sshd: no hostkeys
      > available -- exiting.
      
      1. 所以我把以上文件的权限改成了600

        $ chmod 0600 /etc/ssh_host*

      2. 然后再次调试命令。

        SHA256:4yqAb/GiMfMJPmIXfKz+Zw4fWOCVN7E6vUDHEtokdHk /var/empty 必须由 root 拥有,而不是组或全局可写。

      然后把这个文件夹的权限改成600。

      $ chmod 600 /var/empty
      

      这解决了问题。

      【讨论】:

        猜你喜欢
        • 2018-12-04
        • 2018-03-23
        • 2023-03-09
        • 1970-01-01
        • 2018-02-07
        • 1970-01-01
        • 2019-10-27
        • 1970-01-01
        相关资源
        最近更新 更多