To use ssh-id-copy do you need both id_rsa.pub and id_rsa?

61,143

Solution 1

The ssh-copy-id command from OpenSSH fails if there is no private key file with the same name available, because it tries to login with the specified key to check if it is already present on the remote server.

In recent versions you can override this behavior with the -f switch ("Forced mode").

From the man page:

-f

    Forced mode: doesn't check if the keys are present on the remote server.  This means that it does not need the private key.  Of course, this can result in more than one copy of the key being installed on the remote system.

Solution 2

The .pub is sufficient. You are not in the correct folder.

You can try this :

ssh-copy-id -i /root/.ssh/id_rsa.pub [email protected]

(for the root user : not recommended, it's just an example).

This file is under the .ssh folder on the user folder.

Solution 3

This has been reported as OpenSSH bug #2110.

Solution 4

As mentioned here this is a bug.

Anyway you can simply create an empty file to make it work. In your case:

$ touch ./id_rsa
$ ssh-copy-id -i id_rsa.pub [email protected]

I had the same issue and this worked for me 👍

Share:
61,143

Related videos on Youtube

Admin
Author by

Admin

Updated on September 18, 2022

Comments

  • Admin
    Admin over 1 year

    I am trying to setup a second access ssh key for a friend. He sent me his id_rsa.pub.

    ssh-copy-id -i id_rsa.pub [email protected]
    /usr/local/bin/ssh-copy-id: ERROR: failed to open ID file './id_rsa': No such file or directory
    

    Do I need him to send me both files?

    • Admin
      Admin over 9 years
      @deaghYou don't need to keep a private key secret, you need to keep it secure.
  • tread
    tread almost 8 years
    On mac it needs the -f if you don't have the private key as well, I think
  • init_js
    init_js almost 5 years
    heads up, the ordering of parameters is strict. -f only works as expected if you pass it before the -i argument. ssh-copy-id -i mykey.pub -f otheruser@host just complains, until you move -f at the front.
  • TmTron
    TmTron over 3 years
    and the private key file must not have a file extension (e.g. key.ppk will not work)
  • dave_thompson_085
    dave_thompson_085 over 3 years
    @TmTron: not so; file extensions work fine. OTOH file contents in PPK (Putty Private Key) format do NOT work in OpenSSH, regardless of file name or extension, and many sensible people use extension .ppk to indicate PPK format. PPK format can be converted to/from an OpenSSH format using Puttygen, and there are many existing Qs covering this.
  • TmTron
    TmTron over 3 years
    @dave_thompson_085 This may depend on the version of the ssh-copy-id command. In my case, it does definitely not work when the private key file has an extension, in git-bash (mingw64 on Windows). Maybe that's helpful for someone that comes here...
  • dave_thompson_085
    dave_thompson_085 over 3 years
    @TmTron: okay, with the long weekend I downloaded 'Git for Windows 2.30.0' from git-scm.com and ran git-bash, and ssh -V identifies as OpenSSH 8.4p1 (with OpenSSL 1.1.1i). I created a valid key with ssh-keygen -t rsa -f filename.ppk and ssh-copy-id -i filename.ppk user@host works just fine. filename.otherext also works, as does a name with no extension. Will you please look at the first line of your whatever.ppk file and make sure it is actually a valid OpenSSH keyfile?
  • TmTron
    TmTron over 3 years
    @dave_thompson_085 here's the output of my commands. You can see that I execute the same command twice. First, when the private key-file has the extension .ppk, the command fails. Then I rename the private key-file (remove the extension). Now the same command works. git version 2.23.0.windows.1