scp (secure copy) to ec2 instance without password

Viewed 419378

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?

15 Answers

copy a file from a local server to a remote server

sudo scp -i my-pem-file.pem ./source/test.txt ec2-user@1.2.3.4:~/destination/

copy a file from a remote server to a local machine

sudo scp -i my-pem-file.pem ec2-user@1.2.3.4:~/source/of/remote/test.txt ./where/to/put

So the basically syntax is:-

scp -i my-pem-file.pem username@source:/location/to/file username@destination:/where/to/put

-i is for the identity_file

I've used below command to copy from local linux Centos 7 to AWS EC2.

scp -i user_key.pem file.txt ec2-user@my.ec2.id.amazonaws.com:/home/ec2-user
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.

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.

For ec2 server

#move your key to /tmp or right folder on server

Assign right permission

sudo chmod 600 /tmp/dev-sunrobotics-snippetbucketcom.pem

then connect to server or transfer

scp -i /tmp/dev-snippetbucketcom.pem filestore.tar.gz ubuntu@85.111.5.33.98:/tmp

Make sure in your ip security you have allow ip address to connect

To use PSCP, you need the private key you generated in Converting Your Private Key Using PuTTYgen. You also need the public DNS address of your Linux instance

pscp -i C:\path\my-key-pair.ppk C:\path\Sample_file.txt ec2-user@public_dns:/home/ec2-user/Sample_file.txt
Related