ssh-copy-id not working Permission denied (publickey).

February 6, 2017 2.6k views
DigitalOcean Ubuntu 16.04

Each time I attempt to set up my new Droplet I get stuck right here. ssh-copy-id doesn't work and so I can't get my new user login to work. I've tried some fixes and just gotten more in the weeds. It seems I'm not the only one with this problem but there are different fixes so I'm just going to copy what I'm getting here. I've also tried to copy the key manually like it's mentioned in this tutorial but still no dice... Please help!

/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/Users/USERNAME/.ssh/"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
Permission denied (publickey).

Thanks for any help!

3 Answers

I had trouble using ssh-copy-id for a secondary (non-root) user. ssh-copy-id uses the user's password to connect to the host. New droplets seem to have a setting that prohibits this. I'm not an expert so don't take my word for it.

I fixed it like this:

Log in as root
Edit ssh config:
sudo nano /etc/ssh/sshd_config
Change this line:
PasswordAuthentication no
PasswordAuthentication yes
Restart daemon:
sudo systemctl restart sshd

Do ssh-copy-id:
ssh-copy-id someuser@<my-ip>

Revert changes to ssh_config if you are security conscious and restart daemon.

  • YES!! This worked for me, thanks mjmare!

    • You're welcome.

      In the meantime I discovered that you can use Ansible to (optionally create and) upload a key to DO. And while you're at it, you can automatically create the droplet. Very nice.

Is this issue fixed? Even am facing the same issue since a week. Unable to do ssh-copy-id for the new user created

Have another answer? Share your knowledge.