1

I am trying to transfer a file from my local machine to a remote machine through an intermediate hop.

localmachine -> hop_server -> destination_server

As suggested by https://serverfault.com/a/489479/606674 and https://unix.stackexchange.com/a/317644/142412, I've set up my ~/.ssh/config as follows

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

I can successfully ssh into the destination_server with ssh destination_server, but if I try to copy a local file over with scp test.txt root@destination_server:~/, The connection closes and outputs

scp: Connection closed

It seems like scp doesn't have logs (https://askubuntu.com/a/660153/848577), so,

Firstly, how can I learn more about why the connection was closed?

And secondly, what am I doing wrong?

Edit:

ssh root@destination_server works. So it's not a root permissions issue.

scp -v test.txt root@destination_server:~/ returns the following output

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: curve25519-sha256@libssh.org
debug1: kex: host key algorithm: ssh-ed25519
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: 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 no-more-sessions@openssh.com
debug1: Entering interactive session.
debug1: pledge: filesystem
debug1: client_input_global_request: rtype hostkeys-00@openssh.com 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 eow@openssh.com 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
2cents
  • 123
  • 8
  • 1
    Check out the -v flag under man 1 ssh. You can chain up to three verbosity flags together. Additionally, you can spawn your own instance of sshd with the -d flag and read logs on <stdout>. – Brian Redbeard Apr 08 '23 at 00:01
  • Does "ssh root@destination_server" work ? Perhaps root access is disallowed. – stevea Apr 08 '23 at 09:23

0 Answers0