Reputation: 39816
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 [email protected]:/
Password:
Any ideas why this is happening/how it can be prevented?
Upvotes: 505
Views: 468809
Reputation: 21
Please use this syntax to copy file using scp and key
scp -i [key_file_path] source_path user@hostname:[dest_path]
Upvotes: 2
Reputation: 1206
#move your key to /tmp or right folder on server
sudo chmod 600 /tmp/dev-sunrobotics-snippetbucketcom.pem
scp -i /tmp/dev-snippetbucketcom.pem filestore.tar.gz [email protected]:/tmp
Make sure in your ip security you have allow ip address to connect
Upvotes: 2
Reputation: 3639
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
Upvotes: 66
Reputation: 449
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
Upvotes: 2
Reputation: 26608
Making siliconerockstar's comment an answer since it worked for me
scp -i kp1.pem ./file.txt [email protected]:/home/ec2-user
Upvotes: 22
Reputation: 1371
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
Upvotes: 41
Reputation: 533
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.
Upvotes: 2
Reputation: 71
Just tested:
Run the following command:
sudo shred -u /etc/ssh/*_key /etc/ssh/*_key.pub
Then:
Upvotes: -6
Reputation: 766
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.
Upvotes: 19
Reputation: 970
write this code
scp -r -o "ForwardAgent=yes" /Users/pengge/11.vim [email protected]:/root/
If you have a SSH key with access to the destination server and the source server does not, adding -o "ForwardAgent=yes" will allow you to forward your SSH agent to the source server so that it can use your SSH key to connect to the destination server.
Upvotes: 0
Reputation: 39816
I figured it out. I had the arguments in the wrong order. This works:
scp -i mykey.pem somefile.txt [email protected]:/
Upvotes: 976
Reputation: 3322
lets assume that your pem file and somefile.txt you want to send is in Downloads folder
scp -i ~/Downloads/mykey.pem ~/Downloads/somefile.txt [email protected]:~/
let me know if it doesn't work
Upvotes: 8
Reputation: 11048
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.
Upvotes: 2
Reputation: 71
My hadoopec2cluster.pem
file was the only one in the directory on my local mac, couldn't scp it to aws using scp -i hadoopec2cluster.pem hadoopec2cluster.pem ubuntu@serverip:~
.
Copied hadoopec2cluster.pem to hadoopec2cluster_2.pem and then scp -i hadoopec2cluster.pem hadoopec2cluster_2.pem ubuntu@serverip:~
. Voila!
Upvotes: 3
Reputation: 49
scp -i /home/barkat/Downloads/LamppServer.pem lampp_x64_12.04.tar.gz
this will be very helpful to all of you guys
Upvotes: 4
Reputation: 2007
scp -i /path/to/your/.pemkey -r /copy/from/path user@server:/copy/to/path
Upvotes: 72