0
votes

i am trying to copy files to an EC2 instance with the scp command as follows:

scp -i "key-pair-name.pem" somefile.txt ec2xxxx.us-west-2.compute.amazonaws.com:~

I get the following error: Permission denied (publickey). lost connection

I am using an amazon linux machine

I am able to ssh just fine. I've gone over Q&A here, with no luck.

1
Have you tried add slash to the end of your command? scp -i "key-pair-name.pem" somefile.txt ec2xxxx.us-west-2.compute.amazonaws.com:~/sergiy.dragunov
On Ubuntu images for example the username that has the .pem key is the user ubuntu, thus [email protected]... or -l ubuntuAntti Haapala
@sergiy.dragunov and that is not the problem, the command fails before the path is actually interpreted.Antti Haapala

1 Answers

3
votes

Try specifying the username, eg:

scp -i "key-pair-name.pem" somefile.txt [email protected]:~