本文介绍了Cygwin SSH:使用id_rsa和id_rsa.pub密钥访问远程主机后,连接丢失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



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



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



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

  $ ssh login @ hiddenhost 
连接到由远程主机关闭的hiddenhost 。
与hiddenhost的连接已关闭。

PC003370 + procserver @ ATMPROCSERVER〜
$ ssh -v login @ hiddenhost
OpenSSH_7.2p2,OpenSSL 1.0.2g 2016年3月1日
debug1:读取配置数据/ etc / ssh_config
debug1:连接到hiddenhost [hiddenhost]端口22。
debug1:建立连接。
debug1:身份文件/home/procserver/.ssh/id_rsa类型1
debug1:key_load_public:无此类文件或目录
debug1:身份文件/home/procserver/.ssh/id_rsa-证书类型-1
debug1:key_load_public:无此类文件或目录
debug1:身份文件/home/procserver/.ssh/id_dsa类型-1
debug1:key_load_public:无此类文件或目录
debug1:身份文件/home/procserver/.ssh/id_dsa-cert类型-1
debug1:key_load_public:无此类文件或目录
debug1:身份文件/home/procserver/.ssh / id_ecdsa类型-1
debug1:key_load_public:无此文件或目录
debug1:身份文件/home/procserver/.ssh/id_ecdsa-cert类型-1
debug1:key_load_public:无此类文件或目录
debug1:身份文件/home/procserver/.ssh/id_ed25519类型-1
debug1:key_load_public:无此类文件或目录
debug1:身份文件/ home / procserver /。 ssh / id_ed25519-证书类型-1
debug1:启用协议2.0的兼容模式
debug1:本地版本字符串SSH-2.0-OpenSSH_7.2
debug1:远程协议版本2.0,远程软件版本OpenSSH_7.1
debug1:匹配:OpenSSH_7 .1 pat OpenSSH *兼容0x04000000
debug1:身份验证为hiddenhost:22以'login'
debug1:SSH2_MSG_KEXINIT发送
debug1:SSH2_MSG_KEXINIT收到
debug1:kex:算法:curve25519- [email protected]
debug1:kex:主机密钥算法:ecdsa-sha2-nistp256
debug1:kex:服务器->客户端密码:[email protected] MAC:<隐式
>压缩:无
调试1:kex:客户端->服务器密码:[email protected] MAC:<隐含
>压缩:无
debug1:需要SSH2_MSG_KEX_ECDH_REPLY
debug1:服务器主机密钥:ecdsa-sha2-nistp256 SHA256:TS6tXfpxXyW / KeIWFnvxCsmEhHy8
8NyoBA3DdOHzjFden $ 1 ECDSA主机密钥。
debug1:在/home/procserver/.ssh/known_hosts中找到密钥:1
debug1:在134217728块后重新生成密钥
debug1:SSH2_MSG_NEWKEYS发送了
debug1:需要SSH2_MSG_NEWKEYS
debug1:在134217728块之后重新密钥
debug1:收到SSH2_MSG_NEWKEYS
debug1:SSH2_MSG_SERVICE_ACCEPT收到
debug1:可以继续进行的身份验证:publickey,password,keyboard-interacti
ve
debug1 :下一个身份验证方法:publickey
debug1:提供RSA公钥:/home/procserver/.ssh/id_rsa
debug1:身份验证成功(publickey)。
已验证为hiddenhost([hiddenhost]:22)。
debug1:通道0:新的[client-session]
debug1:请求[email protected]
debug1:输入交互式会话。
debug1:保证:网络
debug1:通道0:空闲:客户端会话,nchannels 1
连接到被远程主机关闭的hiddenhost。
与hiddenhost的连接已关闭。
传输:发送1944,接收1312字节,在0.0秒内
每秒字节:发送647995.5,接收437330.3
debug1:退出状态-1

PC003370 + procserver @ATMPROCSERVER〜
$


解决方案

万岁! !!



我们找到了解决方案。



所有原因都在于拥有/ var / empty /文件夹。我们尝试在调试模式下启动服务器...,然后找到本文:




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

%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 May 7 2010 empty



%chown / var / empty



现在,再次启动sshd。



%/usr/sbin/sshd.exe -D



完成调试并准备运行ss后再次将hd作为服务,将/ var / empty的所有者更改为cyg_server。



%chown cyg_server / var / empty



%cygrunsrv.exe --start sshd



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


My goal is to copy files programatically from remote server to local computer. Both running Windows with Cygwin (server) and computer Cygwin 64.

Before I create rsa or dsa keys I can copy files by entering Password

But after creation of these files, I have "connection closed by remote host. lost connection" error

I gave following rights: "chmod 600 .ssh/id_rsa" (on local computer) and chmod 600 ".ssh/authorized_keys2". What is the problem who can answer to me?

    $ 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: [email protected]
    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: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 [email protected]
    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 ~
    $
解决方案

HURRAY!!!!

We found a solution.

All the reason was in owning /var/empty/ folder. We tried to start server in debuggin mode... and then found this article:

"If you are debugging a SSH connection, you may need to run sshd by hand (instead of as a service) and enable debugging output. Doing so allows you to track exactly why a connection is failing to establish. However, if you try to run sshd by hand, you may get the following message.

% cygrunsrv.exe --stop sshd

% /usr/sbin/sshd.exe -D

Could not load host key: /etc/ssh_host_ecdsa_key/var/empty must be owned by root and not group or world-writable.

To fix this, make the user starting the sshd service the owner of /var/empty.

% ls -ld /var/empty

drwxr-xr-x+ 1 cyg_server root 0 May 7 2010 empty

% chown /var/empty

Now, start sshd again.

% /usr/sbin/sshd.exe -D

When you are done debugging and are ready to run sshd again as a service, change the owner of /var/empty to cyg_server.

% chown cyg_server /var/empty

% cygrunsrv.exe --start sshd

Note: you must have administrator privileges to run"

这篇关于Cygwin SSH:使用id_rsa和id_rsa.pub密钥访问远程主机后,连接丢失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 18:58