I'm trying to copy my public ssh key to my vps, so I can log in with ssh.
However, when I enter the command:
ssh-copy-id me@myserverI get this error message
/usr/local/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/local/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).Does anybody know how to fix this? I'm on a Mac.
22 Answers
As Camilo already suggested, you can add the right SSH public key manually on the remote server.
In my case this same error occurred when the SSH program tried to use a different identity file than defined when using ssh-copy-id or couldn't just find the defined private key / identity file. You can observe what the SSH program does when executing the ssh command by adding -v to it:
ssh -v username@your-host-ip-or-domain Then you just grab on your local machine any public key of which the SSH program tries out the private key, for example (on a Mac/Linux) the default key:
cat ~/.ssh/id_rsa.pub... and add it to the remote's authorized_keys file in:
~/.ssh/authorized_keysAnother, in my case even better solution, was to add a custom host in my local ssh config file. On my Mac it is:
~/.ssh/configHere you can add for example something like this:
Host mynewserver HostName some.IP.number.or.domain Port 20000 #if custom port is used and not the default 22 User the_root PreferredAuthentications publickey IdentityFile ~/.ssh/id_rsa_for_my_new_serverThen you just need to execute:
ssh mynewserver...and Voilà
I had the same problem, the way that worked for me was to put it mannually, in this link you can find how to do it Manually entry. In this way i was able to connect via ssh even when using pair keys. When i was configuring it, the .ssh/authorized_keys file contain another key pointing to the initial machine, so i override that information with the contained in the /.ssh/id_rsa.pub of the initial machine
2