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
---8<----
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?
Best Answer
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:
You can then connect to servers with your username + password:
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:
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 tossh-keygen
.