scp (secure copy) to ec2 instance without password

2019-01-15 23:35发布

I have an EC2 instance running (FreeBSD 9 AMI ami-8cce3fe5), and I can ssh into it using my amazon-created key file without password prompt, no problem.

However, when I want to copy a file to the instance using scp I am asked to enter a password:

scp somefile.txt -i mykey.pem root@my.ec2.id.amazonaws.com:/

Password:

Any ideas why this is happening/how it can be prevented?

12条回答
时光不老,我们不散
2楼-- · 2019-01-16 00:02

I was hung up on this because I was specifying my public key file in

scp -i [private key file path]

When I caught that mistake and changed it to the private key path instead, I was all set.

查看更多
我欲成王,谁敢阻挡
3楼-- · 2019-01-16 00:07

Making siliconerockstar's comment an answer since it worked for me

scp -i kp1.pem ./file.txt ec2-user@1.2.3.4:/home/ec2-user

查看更多
地球回转人心会变
4楼-- · 2019-01-16 00:10
scp -i ~/.ssh/key.pem ec2-user@ip:/home/ec2-user/file-to-copy.txt .

The file name shouldnt be between the pem file and the ec2-user string - that doesnt work. This also allows you to reserve the name of the copied file.

查看更多
▲ chillily
5楼-- · 2019-01-16 00:11

In your case, the user root won't have any issues. But in certain cases where you're required to login under SSH as a different user, make sure the directory you're scp-ing has adequate permissions for the user you're SSH-ing.

查看更多
ら.Afraid
6楼-- · 2019-01-16 00:19

scp -i /home/barkat/Downloads/LamppServer.pem lampp_x64_12.04.tar.gz

this will be very helpful to all of you guys

查看更多
Explosion°爆炸
7楼-- · 2019-01-16 00:20

I figured it out. I had the arguments in the wrong order. This works:

scp -i mykey.pem somefile.txt root@my.ec2.id.amazonaws.com:/
查看更多
登录 后发表回答