amazon-web-servicesamazon-ec2amazon-vpcputty

How to transfer files to EC2 instance in private subnet using a bastion host


I am trying to transfer files to an EC2 instance that is located in a private subnet using a bastion host. My local machine is running Windows, and I am connecting to the EC2 instance via SSH through the bastion host. I am not sure how to transfer files to the EC2 instance from my local machine using only command line tools and Putty.

Here is what I have tried so far: I connected to the bastion host via Putty and then tried to transfer files to the EC2 instance using the scp command on my local pc, but I received Connection timed out error.

Can someone please advise me on how to transfer files to the EC2 instance in the private subnet using a bastion host? Do I need to store my private key on the bastion host, or is there a way to transfer files directly from my local machine to the EC2 instance without storing the private key on the bastion host?

Thanks in advance for your help.


Solution

  • By using the below command and by restricting the key files to chmod 400 I successfully transfer a file from my local pc to my private EC2 instance :

    scp -i "path/to/private/EC2/key" -o ProxyCommand="ssh -i "path/to/bastion/key" ec2-user@bastion_public_ip -W %h:%p" "path/to/file" ec2-user@ec2_private_ip:path