Cannot SCP from Linux EC2 Instance to Local Machine

I'm trying to SCP a file from my Amazon EC2 instance into my Linux machine. I've done quite a bit of reading and nothing seems to work.

I can SSH from my Linux machine into my instance (that's how I connect to it), and can even SCP into it by doingscp -i my-key-pair.pem SampleFile.txt [email protected]:~. According to Amazon's instructions at this link, in order to SCP from the instance to my machine I need only to "simply reverse the order of the host parameters." In other words, this:

scp -i my-key-pair.pem 
[email protected]:~/SampleFile.txt 
~/SampleFile2.txt

I've googled around, and have even read some similar questions on here including this one, but I've had no luck. I'm not sure what the problem is. The other day I managed to SCP across instances (i.e., from one EC2 instance to another) without a problem -- which at least supposedly requires a bit more tinkering.

Another bit that is troubling me as well, is the fact that the command to SCP from the instance to the local machine includes the private key (my-key-pair.pem on the code block above), and I've looked for a .pem file on the instance and have not found one. Am I missing something? Thanks in advance.

By the way, I'm seeing the generic "Permission denied (public key)" error.

Upvotes: 2

Views: 3296

Answers (4)

Santosh A
Santosh A

Reputation: 5351

This command should work First connect to Amazon EC2 over ssh,

scp -i my-key-pair.pem <local file name on Amazon EC2> user_name@<linux_host_ip>:/<copy path>

ex:

scp -i my-key-pair.pem SampleFile2.txt user_name@linuxHostIp:/home/userName/fileName.txt

Upvotes: 1

Danyal
Danyal

Reputation: 458

The IP of your machine is what is expected while scp and not of your router.

Otherwise possibly it might not be able to identify which machine to copy to, and copy all data to all machines behind the router which is not desired.

Possibly that is why it fails.

Upvotes: 0

Bijendra
Bijendra

Reputation: 10035

`scp -r [email protected]:/path/to/foo /home/user/Desktop/`   

-- use above command to scp a folder from server..use -i key if the key used is not the default.

scp -r -i key.pem [email protected]:/path/to/foo /home/user/Desktop/

Upvotes: 1

I found out what the problem was. I was running the command from the instance instead of my local machine, which is somewhat odd given that when you SCP from an instance to another you run the SCP command from the instance you're copying from, but oh well.

Upvotes: 1

Related Questions