20

After a fresh install of Ubuntu 15.10, when using scp or git clone, I get the following warning (the command itself doesn't fail): key_load_public: invalid format

How can I get rid of this warning?

Update: This is the output of scp -vvv:

OpenSSH_6.9p1 Ubuntu-2, OpenSSL 1.0.2d 9 Jul 2015
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug2: ssh_connect: needpriv 0
debug1: Connecting to ... [...] port 22.
debug1: Connection established.
key_load_public: invalid format
debug1: identity file /home/alexzeitler/.ssh/id_rsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/alexzeitler/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/alexzeitler/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/alexzeitler/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/alexzeitler/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/alexzeitler/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/alexzeitler/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/alexzeitler/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.9p1 Ubuntu-2
6
  • There should be more than only a key_load_public: invalid format
    – A.B.
    Nov 17, 2015 at 7:16
  • please, post the whole verbose log.
    – Jakuje
    Nov 17, 2015 at 9:16
  • @Jakuje Added the verbose output to the question. Nov 19, 2015 at 20:50
  • I meant rather verbose log from scp, such as scp -vvv file remote:file or so to see the context from ssh
    – Jakuje
    Nov 19, 2015 at 20:53
  • @Jakuje Updated it again - is this sufficient? Nov 19, 2015 at 21:05

2 Answers 2

35

Check the file /Users/alexzeitler/.ssh/id_rsa. What is there? How did it get there?

It should be your private RSA key, isn't it? And is there something in /Users/alexzeitler/.ssh/id_rsa.pub? Is it valid public key?

If you don't use these keys, remove both of them and the message will disappear. If you are using them in different way, move them somewhere else. The same if they are in different format.

The public part is probably corrupted, so you can recreate it from private one using this command:

ssh-keygen -f ~/.ssh/id_rsa -y > ~/.ssh/id_rsa.pub

###hostkeys possibility The other possibility is that client is trying to read server public keys for HostBasedAuthentication. Don't you have it allowed in /etc/ssh/ssh_config ?

It would be one of these files missing or corrupted:

/etc/ssh/ssh_host_ecdsa_key.pub
/etc/ssh/ssh_host_ed25519_key.pub
/etc/ssh/ssh_host_dsa_key.pub
/etc/ssh/ssh_host_rsa_key.pub

Your sshd server is not complaining?

8
  • The public and private keys are valid when e.g. using them with git + GitHub Nov 19, 2015 at 21:18
  • edited the answer. The server keys can be also the cause in some cases.
    – Jakuje
    Nov 19, 2015 at 21:25
  • 2
    That one was there before. I believe the public part is corrupted somehow. You can try to regenerate new public key from the private using ssh-keygen -y ~/.ssh/id_rsa.
    – Jakuje
    Nov 19, 2015 at 21:54
  • 3
    recreating the public key from the private fixed it - thanks for your help and patience! Please update the answer so I can mark it as answer. Nov 19, 2015 at 22:00
  • 5
    Btw the command I used was: ssh-keygen -f ~/.ssh/id_rsa -y > ~/.ssh/id_rsa.pub Nov 19, 2015 at 22:01
0

I had a similar error Load key "/root/.ssh/id_rsa": invalid format when I tried in a Dockerfile:

RUN echo "$ssh_prv_key" > /root/.ssh/id_rsa &&     chmod 600 /root/.ssh/id_rsa

This led to errors like identity file /root/.ssh/id_rsa type -1 invalid format and read_passphrase: can't open /dev/tty. Do not use echo "${SSH_PRIVATE_KEY}" >> /root/.ssh/id_rsa to pass the private key!

The right way would be to use

COPY id_rsa /root/.ssh/id_rsa
RUN chmod 600 /root/.ssh/id_rsa

The solution explained: my private key was wrongly formatted - instead of many lines, it was passed as a one-liner, and you might have any other format issue like a forgotten "-" at the start or end, or something wrong at the end of the lines, like a missing newline format or an additional letter at the end of a line.

See Dockerfile: clone repo with passwordless private key. Errors: “authentication agent” or “read_passphrase: can't open /dev/tty” for more details, with the main idea from Add private key to ssh-agent in docker file, which again had the idea from Gitlab CI/Docker: ssh-add keeps asking for passphrase.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .