SCP a file into a persistent volume

I have created a volume and need to copy a file into it. When I try using scp I get this error

lost connection
Connection to myapp closed by remote host.

My call is scp priv/private_key.pem root@myapp:/data/private_key.pem

First, you’ll need to follow these instructions to create a wireguard connection locally: Private Networking

Then you can do something like this:

  • flyctl ssh issue --agent: this will register a ssh key with your local agent
  • scp priv/private_key.pem root@myapp.internal:/data/private_key.pem

If you have more than 1 instance, you might need to replace myapp.internal with the actual IP (flyctl ips private)

I have done all that and setup wireguard.
I still get the same error.
Is there an option to get more info | logs when performing scp? Can’t seem to find any.

scp -vvvvv should give you a lot more info!

1 Like
lost connection
debug1: fd 0 clearing O_NONBLOCK
debug3: fd 1 is not O_NONBLOCK
Connection to myapp-api.internal closed by remote host.
Transferred: sent 2868, received 1228 bytes, in 1.1 seconds
Bytes per second: sent 2614.5, received 1119.4
debug1: Exit status -1

My volume name is backend_api_data but mounted as /data That shouldn’t be an issue right?

Should be fine.

Any logs in your instance? The SSH server in the instance might print a few logs.

I’ve never tried to SCP in that direction. I’ve only tried pulling files.

An alternative is to set your private key as a secret with:

cat priv/private_key.pem | flyctl secrets set PRIVATE_KEY_PEM=-

and in your Docker entrypoint you could write that env var to a file in the right spot.

1 Like

The logs print an interesting one:
unexpected error executing command: exec: "scp": executable file not found in $PATH

Looks like that could be the culprit.

I think our ssh implementation is missing some things for scp to work properly. I have a workaround that should do the job quickly for you however:

cat priv/private_key.pem | ssh root@app.internal 'tee /path/to/destination'

This will also echo the file to your shell and then appear to hang. You can CTRL+C to exit and the file should now be on your vm.

1 Like

This worked flawlessly. Thank you.

I am getting the same error, but the solution of using tee didn’t appear to fix my problem.

fly ssh console is working

but using ssh to connect does not:

> ssh root@app.internal
Connection to app.internal closed by remote host.
Connection to app.internal closed.

Did you run fly ssh issue before the ssh command? That generates credentials and provides instructions for using them.

@kurt I did, thanks for checking :+1:

It looks like the ssh connection auths correctly as I see this in the verbose connection

...
debug1: Authentication succeeded (publickey).
Authenticated to app.internal ([fdaa:0:53d7:a7b:2c60:0:ab5b:2]:22).
debug1: channel 0: new [client-session]
...
debug3: send packet: type 98
debug2: channel_input_open_confirmation: channel 0: callback done
debug2: channel 0: open confirm rwindow 2097152 rmax 32768
debug3: send packet: type 1
debug1: channel 0: free: client-session, nchannels 1
debug3: channel 0: status: The following connections are open:
  #0 client-session (t4 r0 i0/0 o0/0 e[write]/0 fd 6/7/8 sock -1 cc -1)

debug3: fd 1 is not O_NONBLOCK
Connection to app.internal closed by remote host.
Connection to app.internal closed.
Transferred: sent 3604, received 1240 bytes, in 0.0 seconds
Bytes per second: sent 88070.0, received 30301.5
debug1: Exit status -1