ssh-copy-id - permission denied (publickey)

Solution 1:

You actually need to login to copy your key, you don't have any access to the remote machine (invalid key and password authentication disabled):

Re-enable passwd authentication in /etc/ssh/sshd_config:

PasswordAuthentication yes

Then restart the service:

service sshd restart

Copy your public key:

ssh-copy-id -i ~/.ssh/id_rsa.pub USER@HOST -p PORT
[Enter user password]

Try to login again, no password should be required.

Then disable password authentication.

Solution 2:

Permission denied (publickey) is the remote SSH server saying "I only accept public keys as an authentication method, go away".

That's your main challenge: Getting onto the remote system. Once you can do that, you can upload your key:

  • Using ssh-copy-id - it will allow you to specify a different key if you're in the process of replacing your old one, for example.
  • Edit the remote user's ~/.ssh/authorized_keys to append your key manually.

Solution 3:

Found the problem finally.

Actually I did not need to copy the public key. Same public key is for both private keys - with passphrase and without passphrase. I thought I have private key without passphrase, but actually I did not. I had only .ppk without passphrase. That was miss communication. So coworker made private key without passphrase and so now I could login using ssh without passphrase. I read that having without passphrase is bad, but coworker says its ok. I needed without passphrase because I need to run shell script on reboot - I want to start autossh on computer reboot.

So kind of solution is this time - if you want to login without passphrase - check if your private key is without passphrase really.

Tags:

Ssh Keys