I can SSH into the EC2 instance:
ssh -i "my_key.pem" ec2-user@my-public-ip
However, scp doesn't work:
scp -r –i "my_key.pem" ./my_file ec2-user@my-public-ip:/home/ec2-user/my_file
Permission denied (publickey).
lost connection
I've also tried using public instance DNS, but nothing changes.
Any idea why is this happening and how to solve it?
The only way for this to happen is the private key mykey.pem
is not found in the current directory. It is possible you tried ssh
from a directory different than scp
.
Try the following with full path to your key:
scp -r –i /path/to/my_key.pem ./my_file ec2-user@my-public-ip:/home/ec2-user/my_file
If it fails, post the output with -v
option. It will tell you exactly where the problem is
scp -v -r –i /path/to/my_key.pem ./my_file ec2-user@my-public-ip:/home/ec2-user/my_file