Unable to scp from one EC2 instance to another EC2 instance

Spicysheep asked:

I am not able to scp from one EC2 instance to another EC2 instance. From my laptop I am able to ssh into each instance without issues.

I have two instances.

#worker1
ec2-107-20-7-57.compute-1.amazonaws.com

#master
ec2-50-19-8-109.compute-1.amazonaws.com

Here is what I have done so far.

I made a new key pair on the master node
ssh-keygen -t dsa

I copy-and-pasted the id_dsa.pub from the master node to my laptop

scp -i ec2key.pem ubuntu@ec2-50-19-8-109.compute-1.amazonaws.com:/home/ubuntu/.ssh/id_dsa.pub /Users/me/somefolder

I copy-and-pasted the id_dsa.pub file from my laptop to the worker node

scp -i ec2key.pem /Users/me/somefolder/id_dsa.pub ubuntu@ec2-107-20-7-57.compute-1.amazonaws.com:/home/ubuntu/.ssh 

On the worker node I appended the id_dsa.pub file to my authorized_keys file

cat id_dsa.pub >> authorized_keys

I created a file on the master node: /home/ubuntu/test.txt and then tried to scp this file from the master node to the worker node

scp -v -i ubuntu@ec2-50-19-8-109.compute-1.amazonaws.com:/home/ubuntu/.ssh/id_dsa ubuntu@ec2-50-19-8-109.compute-1.amazonaws.com:/home/ubuntu/test.txt ubuntu@ec2-107-20-7-57.compute-1.amazonaws.com:

I got the following result

Permission denied (publickey).

Any ideas?

Additional details:

My answer:


Use ssh-copy-id to ensure that the key is copied correctly and that permissions on the relevant files/directories are correct.

If your system doesn’t include the command ssh-copy-id you can get it from the following openssh repo. openssh project repo & link to openssh-copy-id


View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.