2
votes

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.

4
What is the error that you see? If you support user/pwd logins to your local machine you would not need the .pem file. Do you have a static ip that resolves to your local machine, though?TJ-
I'm seeing the "Permission denied (public key)" error. I've used the verbose (-v) tag to learn more about the error, have gotten "No more authenticaton methods to try." What do you mean by user/password logins? And no, I don't have a static IP to my machine, but according to Amazon I don't need one. It should work.René Alejandro Santiago
I think you need to change the permissions of your key. chmod 600 my-key-pair.pem. By username/password login, I am referring to the fact that you can use username and password for logging in instead of the .pem file. Regarding IPs - If you are ssh-ing FROM ec2 to your local machine how would you expect your machine to be uniquely identified?TJ-
I found out what the problem was. I was running the command from the instance instead of my local machine: "use the following command on your local computer."René Alejandro Santiago

4 Answers

1
votes

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.

1
votes
`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/

1
votes

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

0
votes

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.