During the last years I've had various problems with MacOS SSH, but those were quickly resolved searching the net. This is now something different.

This is Mojave -system with lates updates (10.14.4). I do think though that this did begin even before updating with the latest patches.

$ ssh -V
OpenSSH_7.9p1, LibreSSL 2.7.3

The error I get is:

$ ssh <host> -v
debug1: no key from blob. pkalg ssh-rsa: invalid format
ssh_dispatch_run_fatal: Connection to <host> port 22: invalid format

I've tried running without defined config-file, running with different options, but with no help. From other systems, such as Arch Linux (OpenSSH_7.9p1) and CentOS7 (OpenSSH_7.4p1) ssh'ing to the same host works well. Especially the same SSH version working on an arch linux tells me that this is something apple-related.

So what is happening now and how to fix this behaviour?

  • 1
    Sounds like your key is corrupt - serverfault.com/questions/854208/…. – slm Apr 8 at 18:26
  • Is there a way to force authentication without a key? Other than moving that away from the .ssh-directory? – SWTM Apr 9 at 9:44

That error sounds like your SSH key may be corrupt. This SF Q&A titled: SSH Suddenly returning Invalid format mentions it as well with that same conclusion.

Your options are to either regenerate a new SSH key or try connecting using just your username + password.

Force SSH password method

To force SSH to use the password method for establishing a connection you can use this alias like so:

$ alias sshno='ssh -o PreferredAuthentications=password -o PubkeyAuthentication=no -o ControlPath=none'

You can then connect to servers with your username + password:

$ sshno <user>@<server>

Problem with SSH key length

In more recent versions of OSX Apple decided to drop support for keys that were < 2048 bits in length. This was apparently done with the migration to Sierra as discussed in this article titled: Upgrading to macOS Sierra will break your SSH keys and lock you out of your own servers.

You can verify your SSH key-pair's length like so:

$ ssh-keygen -lf ~/.ssh/ssh_slm@keynum1_id_rsa.pub
4096 SHA256:mwvSCr2CO5RXjML2EhgERTHgGB23JgRegB23Th34aeT slm@somedom.com (RSA)

This shows that my key's length is 4096 bits. You can generate a SSH key-pair with a specific length by using the -b switch to ssh-keygen.

$ ssh-keygen -b 4096 ....
  • That answered my questions. The key, either locally or at the target host, seems to be the problem. Keylength is 4096, if that interests somebody. Thanks slm – SWTM Apr 10 at 9:57

It may be that your keys are corrupted, as this issue is seen after some hardware failures. Try backing up and removing /etc/ssh/ssh_host_* and generating the missing keys with ssh-keygen -A.

You must log in to answer this question.

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