I am on Amazon AWS and I have two EC2 instance on my account. Trying to send rsa key via SSH to another EC2 instance using internal private IP. But its not working.
scp -i .ssh/id_rsa.pub xxx.xxx.xxx.xxx:/root/.ssh/authorized_keys2
What am I doing wrong and how do I send file to another EC2 account with ssh.
Here the scp format:
scp -i <key> <what_to_copy> <where_to_copy>
You are missing
<what_to_copy>
in the example.Also check the security group of the target server. It should allow the connections either the the security group of the source sever or from the
10.0.0.0/8
network.This won't completely replace the authorized_keys file, so you can continue logging in with previous access:
where "USER" might be "root", "ec2-user", or "ubuntu", depending on the AMI you are running.
Or, just start your EC2 instances using your personal ssh keys in the first place. Here's an article I wrote about that:
You are probably using the 10.x.x.x-ip of the instance. This won't work. Use the external path. (something like
ec2-75-102-166-16.compute-1.amazonaws.com
). Or attach an elastic IP to it and use that.I've moved my key to
~/.ssh
then created the file~/.ssh/config
(or appended to it) with:This will let you ssh and scp without ever specifying the key location.
I had this same issue today. Here is my script for a number of files:
I hope this helps! :)