1

Trying to log into a server, I've messed the ssh auto login without keys trying to add a key.

When I try here's the issue I'm getting

samuel@samuel-pc:~/Documents/code/revamp$ ssh-copy-id root@67.205.154.128
/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).


samuel@samuel-pc:~/Documents/code/revamp$ cat ~/.ssh/id_rsa.pub | ssh root@67.205.154.128 "mkdir -p ~/.ssh && cat >>  ~/.ssh/authorized_keys"
Permission denied (publickey).

samuel@samuel-pc:~/Documents/code/revamp$ ssh root@67.205.154.128
Permission denied (publickey).
0

You have to specify the key

ssh-copy-id -i .ssh/id_rsa.pub root@67.205.154.128

See http://bodhizazen.com/Tutorials/SSH_keys/#ssh-copy-id for details / additional information.

You can not use ssh-copy-id to transfer your key unless you can log in via another method (ie password).

If you can not read the key, then in addition you have a permissions problem. The key should be owned by your user (not root) and permissions of 400 or 440.

5
  • You can not copy the public key when the password authentication is not allowed.
    – Jakuje
    Jul 14 '17 at 9:00
  • @Jakuje - Yes, that information is already in my answer
    – Panther
    Jul 14 '17 at 15:33
  • But there is a lot of unrelated, confusing and generic information around. Downvoting my answer does not make your answer better.
    – Jakuje
    Jul 14 '17 at 15:36
  • You are free to do as you wish. IMO you need to specify the key , otherwise it is ambiguous to both ssh and ssh-copy-id which key to use. My answer is complete as it addresses both 1. you need to be able to log in via another method (could be host based or password) and 2. Default ownership and permissions of the key,
    – Panther
    Jul 14 '17 at 15:44
  • 1) No, you do not need to specify key if it is in the default location (as the OP one is). See the manual page. 2) your example would not work from anywhere else then in home directory, because you miss the ~/ in front of the key. 3) Nothing else then different authentication method or physical access can not resolve the messed up configuration 4) I believe you are here also long enough to know how it works. Misleading and wrong answers do not get upvotes.
    – Jakuje
    Jul 14 '17 at 15:52
-1
Permission denied (publickey).

means that the only allowed authentication method is public key and it did not work. For ssh-copy-id you usually need to have different method allowed (password) to initially connect to the server and set up the key.

At this point, it is not possible to copy your key using ssh-copy-id and you will need either somebody who still has the access to that server, remote console, or physical access to set up the key/allow password authentication.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.