scp (secure copy) to ec2 instance without password

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

scp -i mykey.pem somefile.txt [email protected]:/

scp -i /path/to/your/.pemkey -r /copy/from/path user@server:/copy/to/path

copy a file from a local server to a remote server

sudo scp -i my-pem-file.pem ./source/test.txt [email protected]:~/destination/

copy a file from a remote server to a local machine

sudo scp -i my-pem-file.pem [email protected]:~/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 [email protected]:/home/ec2-user