Score:0

SCP to an EC2 instance is failing but SSH works

ba flag

I'm trying to scp a jar file to an EC2 instance that hosts a service I'm working on. I'm able to ssh into that EC2 instance without issue. When I attempt to scp the file with the following command:

scp -vvv foo.jar instance-id:/tmp/

I'm prompted for a password and then get the following output after I authenticate

debug1: Authentication succeeded (password).
Authenticated to <instance id> (via proxy).
...
debug1: Entering interactive session.
debug1: pledge: filesystem full
...
debug1: Sending command: scp -v -t /tmp/
debug2: channel 0: request exec confirm 1
debug2: channel_input_open_confirmation: channel 0: callback done
debug2: channel 0: open confirm rwindow 0 rmax 32768
debug2: channel 0: rcvd adjust 2097152
debug2: channel_input_status_confirm: type 99 id 0
debug2: exec request accepted on channel 0
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug1: client_input_channel_req: channel 0 rtype [email protected] reply 0
debug2: channel 0: rcvd eow
debug2: chan_shutdown_read: channel 0: (i0 o0 sock -1 wfd 3 efd 7 [write])
debug2: channel 0: input open -> closed
debug2: channel 0: rcvd eof
debug2: channel 0: output open -> drain
debug2: channel 0: obuf empty
debug2: chan_shutdown_write: channel 0: (i3 o1 sock -1 wfd 6 efd 7 [write])
debug2: channel 0: output drain -> closed
debug2: channel 0: rcvd close
debug3: channel 0: will not send data after close
debug2: channel 0: almost dead
debug2: channel 0: gc: notify user
debug2: channel 0: gc: user detached
debug2: channel 0: send close
debug3: send packet: type 97
lost connection
debug2: channel 0: is dead
debug2: channel 0: garbage collecting
debug1: channel 0: free: client-session, nchannels 1
debug3: channel 0: status: The following connections are open:
  #0 client-session (t4 r0 i3/0 o3/0 e[write]/0 fd -1/-1/7 sock -1 cc -1)

debug3: send packet: type 1
debug1: fd 0 clearing O_NONBLOCK
debug3: fd 1 is not O_NONBLOCK
Transferred: sent 2752, received 2780 bytes, in 0.3 seconds
Bytes per second: sent 9360.6, received 9455.8
debug1: Exit status 1

ssm-agent logs

2022-11-17 22:08:20 INFO  inter process communication started at /var/lib/amazon/ssm/<instance id>/channels/<channel>
2022-11-17 22:08:20 INFO Running plugin Port Port
2022-11-17 22:08:20 INFO Setting up datachannel for session: <channel>, requestId: 50dfe339-7d47-41e4-9cd2-18eb4020e83e, clientId:
2022-11-17 22:08:20 INFO Opening websocket connection to: wss://ssmmessages.us-east-1.amazonaws.com/v1/data-channel/<channel>?role=publish_subscribe
2022-11-17 22:08:20 INFO Successfully opened websocket connection to: wss://ssmmessages.us-east-1.amazonaws.com/v1/data-channel/<channel>?role=publish_subscribe
2022-11-17 22:08:20 INFO Starting websocket pinger
2022-11-17 22:08:20 INFO Starting websocket listener
2022-11-17 22:08:20 INFO Initiating Handshake
2022-11-17 22:08:20 INFO Client side session manager plugin version is: 1.2.398.0
2022-11-17 22:08:20 INFO Handshake successfully completed.
2022-11-17 22:08:20 INFO Plugin Port started
2022-11-17 22:08:28 INFO TCP Connection was closed.
2022-11-17 22:08:28 INFO Closing datachannel with channel Id <channel>
2022-11-17 22:08:28 INFO Closing websocket channel connection to: wss://ssmmessages.us-east-1.amazonaws.com/v1/data-channel/<channel>?role=publish_subscribe
2022-11-17 22:08:28 INFO Ending websocket pinger
2022-11-17 22:08:28 INFO Ending the channel listening routine since the channel is closed
2022-11-17 22:08:28 INFO Ending websocket listener
2022-11-17 22:08:28 INFO Successfully closed websocket connection to: 67.220.242.9:443
2022-11-17 22:08:28 INFO Sending plugin Port completion message
2022-11-17 22:08:28 INFO document execution complete
2022-11-17 22:08:28 INFO sending document complete response...
2022-11-17 22:08:28 INFO stopping ipc worker...
2022-11-17 22:08:28 INFO requested shutdown, prepare to stop messaging
2022-11-17 22:08:28 INFO channel /var/lib/amazon/ssm/<instance id>/channels/<channel> requested close
2022-11-17 22:08:28 INFO worker listener stopped on path: /var/lib/amazon/ssm/<instance id>/channels/<channel>
2022-11-17 22:08:28 INFO channel /var/lib/amazon/ssm/<instance id>/channels/<channel> closed
2022-11-17 22:08:28 INFO ipc channel closed, stop messaging worker
2022-11-17 22:08:28 INFO requested terminate messaging worker, destroying the channel
2022-11-17 22:08:28 INFO Session worker closed
2022-11-17 22:08:28 INFO channel /var/lib/amazon/ssm/<instance id>/channels/<channel> requested close
2022-11-17 22:08:28 INFO Closed the file watcher listener thread
2022-11-17 22:08:28 INFO master listener stopped on path: /var/lib/amazon/ssm/<instance id>/channels/<channel>
2022-11-17 22:08:28 INFO sending reply for plugin update: Port
2022-11-17 22:08:28 INFO Done
2022-11-17 22:08:28 INFO sending document: <channel> complete response
2022-11-17 22:08:28 INFO received plugin: Port result from Processor
2022-11-17 22:08:28 INFO session: <channel> complete
2022-11-17 22:08:28 INFO received reply for SessionResult <channel> with message id ea77f702-1628-46ad-b94e-6b7d7f6998dc

As far as I can tell I'm successfully connecting to the host. It seems like the file transfer immediately exits afterwards. scp fails in both directions: I can't go from remote to local or local to remote. I noticed in the ssm logs that the handshake succeeds and then the TCP connection immediately closes. I've done some digging on similar questions and responders have said that this can indicate shell problems. I've gone through my zshrc and haven't found any lines that could be breaking scp.

Tim avatar
gp flag
Tim
Try SFTP (SSH file transfer protocol)
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.