Why can't I ssh-copy-id to an EC2 instance?

9

6

I have a ubuntu Natty instance on EC2, and I can SSH into it by

ssh -v -i ec2-keypair ubuntu@ubuntu@XXXX.compute-1.amazonaws.com

But I'd like to set up password less sshing. So I tried these options and nothing is working:

 $ ssh-copy-id -i ~/.ssh/id_rsa.pub ubuntu@XXXX.compute-1.amazonaws.com
Permission denied (publickey).

 $ ssh-copy-id -i ~/.ssh/ec2-keypair ubuntu@XXXX.compute-1.amazonaws.com
/usr/bin/ssh-copy-id: ERROR: No identities found

 $ ssh-copy-id -i ~/.ssh/id_rsa.pub root@XXXX.compute-1.amazonaws.com
Permission denied (publickey).

Jeremy Smith

Posted 2011-09-02T16:11:06.423

Reputation: 387

Answers

19

I needed to run

ssh-add ~/.ssh/ec2-keypair

Jeremy Smith

Posted 2011-09-02T16:11:06.423

Reputation: 387

I have done this for both postgres and my admin normal user still when I run ssh-copy-id -f -i /var/lib/postgres/.pubfilename ubuntu@ec2-domain still getting permission denied error. – Piyush S. Wanare – 2017-03-20T07:48:02.973

Note in some environments, you'll need to run eval "$(ssh-agent)" if you see Could not open a connection to your authentication agent – azatar – 2017-10-13T23:04:19.450

1

I had the same problem: ssh-copy-id gives the error Permission denied (publickey) on an AWS EC2 instance. I was sure that I set all the permissions correctly using chmod.

In addition, I needed to change this line in /etc/ssh/sshd_config from

PasswordAuthentication no

to

PasswordAuthentication yes

I guess that's because ssh-copy-id asks for your password.

Then the error disappeared.

Steve Tjoa

Posted 2011-09-02T16:11:06.423

Reputation: 111

Beware though that changing the PasswordAuthentication from 'no' to 'yes' can lock you out of your EC2 instance. – Kingz – 2014-07-08T23:57:17.043