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.