我正在尝试通过两台服务器设置无密码连接,第一台 (A) 运行带有 Cygwin 的 Win 服务器,第二台运行 Debian Linux。我遵循了以下指南:http://troy.jdmz.net/rsync/index.html, 所以:
1.DEB 服务器
1.a. 创建密钥:
ssh-keygen -t rsa -b 2048 -f /home/deb-user/cron/deb-rsync-key
1.b 使用 scp 和身份验证在 Win 服务器上复制 deb-rsync-key.pub
2.Win服务器
2.a 使用 ssh 和身份验证进入 Win 服务器并进入deb-rsync-key.pub
文件夹,然后复制我创建的文件.ssh
中的内容authorized_keys
2.b 确保.ssh
文件夹具有700
权限和authorized_keys
文件600
。
2.c 确保RSAAuthentication
和PubkeyAuthentication
键/etc/sshd/sshd_config
均未注释,并且yes
2.d 尝试将 设置AuthorizedKeysFile
为指向autorized_keys
用户主文件夹中文件的绝对路径(从 更改.ssh/autorized_keys
为/home/win-user/.ssh/autorized_keys
)
2.e 重新启动 sshd 服务器(net stop sshd
,net start sshd
)
3.Deb 服务器
尝试使用密钥访问 win 服务器:
ssh -i /home/deb-user/cron/deb-rsync-key win-user@win-host
我得到的是
Connection closed by win-host
DEB 中未记录任何内容:/var/logs/auth.log
WIN 中没有记录任何内容:/var/logs/sshd.log
任何帮助都感激不尽!
更新: 在 ssh 命令中添加 -v 选项将返回以下内容:
OpenSSH_5.5p1 Debian-6+squeeze3, OpenSSL 0.9.8o 01 Jun 2010
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to win-host [win-host] port 22.
debug1: Connection established.
debug1: identity file /home/deb-user/cron/deb-rsync-key.pub type 1
debug1: Checking blacklist file /usr/share/ssh/blacklist.RSA-2048
debug1: Checking blacklist file /etc/ssh/blacklist.RSA-2048
debug1: identity file /home/deb-user/cron/deb-rsync-key.pub-cert type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.0
debug1: match: OpenSSH_6.0 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.5p1 Debian-6+squeeze3
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
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
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Host 'win-host' is known and matches the RSA host key.
debug1: Found key in /home/deb-host/.ssh/known_hosts:2
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug1: Next authentication method: publickey
debug1: Offering public key: /home/deb-host/cron/deb-rsync-key.pub
Connection closed by win-host
更新2 win服务器.ssh文件夹权限如下:
$ ls -la .ssh
total 6
drwx------+ 1 win-user Domain Users 0 Mar 12 10:26 .
drwxr-xr-x+ 1 win-user Domain Users 0 Mar 12 10:25 ..
-rw------- 1 win-user Domain Users 396 Mar 12 10:26 authorized_keys
-rw------- 1 win-user Domain Users 396 Mar 12 10:24 deb-rsync-key.pub
更新3: DEB服务器中的文件夹权限如下:
$ ls -la /home/
total 16
drwxr-xr-x 4 root root 4096 31 gen 11.19 .
drwxr-xr-x 22 root root 4096 28 gen 11.59 ..
drwx------ 18 deb-user deb-user 4096 12 mar 11.15 deb-user
Win服务器中的文件夹权限如下:
$ ls -la /home/
total 8
drwxrwxrwt+ 1 jbogdani root 0 Oct 20 2011 .
drwxr-xr-x+ 1 jbogdani root 0 Nov 1 00:44 ..
drwx------+ 1 win-user Domain Users 0 Mar 12 10:25 win-user
更新4 更详细:
$ ssh -vvv -i /home/de-user/cron/deb-rsync-key win-user@win-host
OpenSSH_5.5p1 Debian-6+squeeze3, OpenSSL 0.9.8o 01 Jun 2010
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug2: ssh_connect: needpriv 0
debug1: Connecting to win-host [win-host] port 22.
debug1: Connection established.
debug3: Not a RSA1 key file /home/deb-user/cron/deb-rsync-key.
debug2: key_type_from_name: unknown key type '-----BEGIN'
debug3: key_read: missing keytype
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug2: key_type_from_name: unknown key type '-----END'
debug3: key_read: missing keytype
debug1: identity file /home/deb-user/cron/deb-rsync-key type 1
debug1: Checking blacklist file /usr/share/ssh/blacklist.RSA-2048
debug1: Checking blacklist file /etc/ssh/blacklist.RSA-2048
debug1: identity file /home/deb-user/cron/deb-rsync-key-cert type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.0
debug1: match: OpenSSH_6.0 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.5p1 Debian-6+squeeze3
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: ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,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,ecdsa-sha2-nistp256
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-256-96,hmac-sha2-512,hmac-sha2-512-96,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-256-96,hmac-sha2-512,hmac-sha2-512-96,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: 139/256
debug2: bits set: 528/1024
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug3: check_host_in_hostfile: host win-host filename /home/deb-user/.ssh/known_hosts
debug3: check_host_in_hostfile: host win-host filename /home/deb-user/.ssh/known_hosts
debug3: check_host_in_hostfile: match line 2
debug1: Host 'win-host' is known and matches the RSA host key.
debug1: Found key in /home/deb-user/.ssh/known_hosts:2
debug2: bits set: 506/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: /home/deb-user/cron/deb-rsync-key (0xb8f465c0)
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug3: start over, passed a different list publickey,password,keyboard-interactive
debug3: preferred gssapi-keyex,gssapi-with-mic,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 public key: /home/deb-user/cron/deb-rsync-key
debug3: send_pubkey_test
debug2: we sent a publickey packet, wait for reply
Connection closed by win-host
答案1
我认为问题出在你的authorized_keys上,或者可能是你服务器上没有安装 rsync。
首先检查rsync是否安装,然后我们尝试按步骤解决问题:
首先,让我们摆脱来自=和命令=,这样我们就能知道它是否可以使用密钥进行连接。
得到的行应如下所示:
ssh-dss AAAAB3NzaC1kc3MAAAEBA..
然后我们看看是否可以直接使用 ssh 连接。
ssh -i [密钥路径] win-user@win-host
如果可行,我们添加ip=,确保它是连接的客户端的IP。
ip="[客户端 ip]" ssh-dss AAAAB3NzaC1kc3MAAAEBA ..
尝试使用上面的 ssh 命令再次连接。
最后,让我们添加验证-rsync。
ip="[客户端 ip]",命令="/home/remoteuser/cron/validate-rsync" ssh-dss AAAAB3NzaC1kc3MAAAEBA ..
现在,使用/home/remoteuser/cron/validate-rsync,你将无法直接使用 ssh,因为脚本会阻止默认 shell(在密码文件 /etc/passwd)。
verify-rsync 用于阻止除以下命令之外的所有命令rsync --服务器。相反,您应该尝试从客户端到服务器的简单 rsync。
触摸测试 && rsync -vv -e “ssh -i 路径到密钥” 测试 win-user@win-host
它也可能与 cygwin 有关,请查看此消息: