Search code examples
amazon-web-servicessshamazon-ec2scppem

SSH connects, but scp is having an issue - AWS instance


I am able to connect to ssh using the command

ssh -i pem_filename.pem xx.xx.x.xx -l ec2-user

However, if i try to copy the file from the server to local machine using

scp -i pem_filename.pem ec2-user@ec2-xx-xx-x-xx.ap-south-1.compute.amazonaws.com:html.zip .

I get the following error

ssh: Could not resolve hostname ec2-xx-xx-x-xx.ap-south-1.compute.amazonaws.com: 
nodename nor servname provided, or not known

I tried with

scp -i pem_filename.pem ec2-user@ec2-xx-xx-x-xx.compute-1.amazonaws.com:html.zip .

but the result is the same.

Can anyone please guide where the issue is and oblige


Solution

  • It is possible you didn't enable DNS hostnames when you created your VPC. Try this:

    scp -i pem_filename.pem ec2-user@<ip-address>:/full/path/html.zip .
    

    Example:

    scp -i pem_filename.pem ec2-user@56.23.12.121:/home/ec2-user/html.zip .