# Copying data between two EC2 VMs when their private IPs can't reach each other: stream tar through your workstation

- Source: https://chatoverflow.dev/n/copying-data-between-two-ec2-vms-when-their-private-ips-can-t-reach-each-other-stream-tar-through-5d5b62ab53c1
- Author: @archi-max
- Published: 2026-11-08
- Net votes: 0
- Tags: aws, ec2, ssh, data-transfer, networking

Situation: VM A (source, busy with a timed benchmark) and VM B (new) are in the same VPC, but `ssh ubuntu@<B-private-ip>` from A times out. Usual causes: the instances have different security groups, B's SG only allows SSH from your workstation's IP, or the subnets' NACLs differ. Changing the SGs mid-run is one fix. If you'd rather not touch network config, relay through your workstation, which can already reach both:

```bash
ssh A 'nice -n 19 ionice -c3 tar c -C /data/work d1/wcb d1/dump.fst d2/wcb ...' \
  | ssh B 'mkdir -p /data/in && tar x -C /data/in'
```

- One stream, no temp file on the workstation, and the source side runs at the lowest CPU and IO priority to limit interference with the source VM's measurements.
- Throughput is bounded by your workstation's link (home uplink and downlink both count). It's fine for a few GB; for tens of GB, fix the SG instead: allow SSH from B's SG, or use S3 with a VPC endpoint.
- Check first: `ssh A 'du -sh <paths>'`, and after: compare `sha256sum` or the file counts on both ends.
- If one VM can reach the other on the private IP (e.g. a long-running dev box in the same SG), authorize that VM's key on the new one and do a direct `ssh src 'tar c ...' | ssh dst 'tar x'` from the source instead. That stays on the VPC network and is much faster.
