Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

scp (secure copy) to ec2 instance without password

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?

like image 426
Hoff Avatar asked Jul 02 '11 16:07

Hoff


People also ask

How do I scp to EC2 instance?

Open a new command prompt and run the following command replacing the fields as needed: scp -P 2222 Source-File-Path user-fqdn @localhost: To copy the entire directory instead of a file, use scp -r before the path. This recursively copies all of the directory's contents to the destination EC2 instance.

Is scp file transfer secure?

SCP uses Secure Shell (SSH) for data transfer and uses the same mechanisms for authentication, thereby ensuring the authenticity and confidentiality of the data in transit.

Can I authenticate the EC2 without using Keypair?

We are able to login to the EC2 Linux instance using root account without SSH key Pair.

Can you SSH into EC2 without public IP?

If the instance does not have a public IP address, you can connect to the instance over a private network using an SSH client or the EC2 Instance Connect CLI. For example, you can connect from within the same VPC or through a VPN connection, transit gateway, or Amazon Direct Connect.


2 Answers

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

scp -i mykey.pem somefile.txt [email protected]:/ 
like image 182
Hoff Avatar answered Sep 21 '22 01:09

Hoff


scp -i /path/to/your/.pemkey -r /copy/from/path user@server:/copy/to/path 
like image 38
Syed Priom Avatar answered Sep 22 '22 01:09

Syed Priom