多跳 ssh 可以工作,但 scp 会因“连接已关闭”而关闭

多跳 ssh 可以工作,但 scp 会因“连接已关闭”而关闭

我正在尝试通过中间跃点将文件从本地计算机传输到远程计算机。

本地机器 -> hop_server -> 目的地服务器

正如建议的https://serverfault.com/a/489479/606674https://unix.stackexchange.com/a/317644/142412,我已按如下方式设置 ~/.ssh/config

Host hop_server
HostName hop_server
User username
IdentityFile ~/.ssh/hop_key
                       
Host destination_server
User root
ProxyCommand ssh -W %h:%p hop_server          
IdentityFile ~/.ssh/destination_key

我可以使用 ssh 成功连接到目标服务器ssh destination_server,但是如果我尝试使用 复制本地文件scp test.txt root@destination_server:~/,连接将关闭并输出

scp:连接已关闭

好像 scp 没有日志(https://askubuntu.com/a/660153/848577), 所以,

首先,我如何才能详细了解连接关闭的原因?

其次,我做错了什么?

编辑:

ssh root@destination_server作品。所以这不是root权限问题。

scp -v test.txt root@destination_server:~/返回以下输出

Executing: program /usr/bin/ssh host destination_server, user root, command sftp
OpenSSH_9.2p1 Debian-2, OpenSSL 3.0.8 7 Feb 2023
debug1: Reading configuration data /home/username/.ssh/config
debug1: /home/username/.ssh/config line 5: Applying options for destination_server
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files
debug1: /etc/ssh/ssh_config line 21: Applying options for *
debug1: Executing proxy command: exec ssh -W destination_server:22 hop_server
debug1: identity file /home/username/.ssh/id_ecdsa type 2
debug1: identity file /home/username/.ssh/id_ecdsa-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_9.2p1 Debian-2
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.1
debug1: compat_banner: match: OpenSSH_7.1 pat OpenSSH_7.0*,OpenSSH_7.1*,OpenSSH_7.2*,OpenSSH_7.3*,OpenSSH_7.5*,OpenSSH_7.6*,OpenSSH_7.7* compat 0x04000002
debug1: Authenticating to destination_server:22 as 'root'
debug1: load_hostkeys: fopen /home/username/.ssh/known_hosts2: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: [email protected]
debug1: kex: host key algorithm: ssh-ed25519
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: SSH2_MSG_KEX_ECDH_REPLY received
debug1: Server host key: ssh-ed25519 
debug1: load_hostkeys: fopen /home/username/.ssh/known_hosts2: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory
debug1: Host 'destination_server' is known and matches the ED25519 host key.
debug1: Found key in /home/username/.ssh/known_hosts:8
debug1: rekey out after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey in after 134217728 blocks
debug1: get_agent_identities: bound agent to hostkey
debug1: get_agent_identities: agent returned 1 keys
debug1: Will attempt key: ED25519 agent
debug1: Will attempt key: /home/username/.ssh/id_ecdsa ECDSA explicit
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Offering public key: ED25519 agent
debug1: Authentications that can continue: publickey,password
debug1: Offering public key: /home/username/.ssh/id_ecdsa ECDSA explicit
debug1: Server accepts key: /home/username/.ssh/id_ecdsa ECDSA explicit
Authenticated to destination_server (via proxy) using "publickey".
debug1: channel 0: new session [client-session] (inactive timeout: 0)
debug1: Requesting [email protected]
debug1: Entering interactive session.
debug1: pledge: filesystem
debug1: client_input_global_request: rtype [email protected] want_reply 0
debug1: client_input_hostkeys: searching /home/username/.ssh/known_hosts for destination_server / (none)
debug1: client_input_hostkeys: searching /home/username/.ssh/known_hosts2 for destination_server / (none)
debug1: client_input_hostkeys: hostkeys file /home/username/.ssh/known_hosts2 does not exist
debug1: Sending environment.
debug1: channel 0: setting env LANG = "en_US.UTF-8"
debug1: Sending subsystem: sftp
debug1: client_global_hostkeys_prove_confirm: server used untrusted RSA signature algorithm ssh-rsa for key 0, disregarding
debug1: update_known_hosts: known hosts file /home/username/.ssh/known_hosts2 does not exist
debug1: pledge: fork
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug1: client_input_channel_req: channel 0 rtype [email protected] reply 0
debug1: channel 0: free: client-session, nchannels 1
Transferred: sent 2808, received 2776 bytes, in 0.2 seconds
Bytes per second: sent 14229.8, received 14067.6
debug1: Exit status 127
scp: Connection closed

相关内容