When I try to connect my Mac, then I get this error.
I read a log where to found it:
System.NotSupportedException: Key 'OPENSSH' is not supported.
at Renci.SshNet.PrivateKeyFile.Open(Stream privateKey, String passPhrase)
at Renci.SshNet.PrivateKeyFile..ctor(String fileName, String passPhrase)
at Xamarin.Messaging.Ssh.MessagingAuthenticationMethod.InitializePrivateKeyAuthentication(String username, ISshInformationProvider sshInformationProvider) in E:\A\_work\157\s\External\messaging\src\Xamarin.Messaging.Ssh\MessagingAuthenticationMethod.cs:line 76
at Xamarin.Messaging.Ssh.MessagingService.GetMessagingConnection(Func`1 passwordProvider, ISshInformationProvider sshInformationProvider) in E:\A\_work\157\s\External\messaging\src\Xamarin.Messaging.Ssh\MessagingService.cs:line 418
at Xamarin.Messaging.Ssh.MessagingService.<ConnectAsync>d__64.MoveNext() in E:\A\_work\157\s\External\messaging\src\Xamarin.Messaging.Ssh\MessagingService.cs:line 167
I found library and code that it's using:
https://github.com/sshnet/SSH.NET/blob/bd01d971790a7c1fa73bad35b79ada90bf69e62d/src/Renci.SshNet/PrivateKeyFile.cs#L190
and there is nothing about OpenSSH like a keyName.
I check my private keys in folder %LOCALAPPDATA%\Xamarin\MonoTouch:
-----BEGIN OPENSSH PRIVATE KEY-----
...
-----END OPENSSH PRIVATE KEY-----
I began to receive this error when I reinstalled Windows 10 and Visual Studio 2017 instead of Windows 7
Please help me solve it
I execute below command in command-prompt, and retry connecting Mac.
ssh-keygen -t rsa -b 8192 -N "" -f "%LOCALAPPDATA%\Xamarin\MonoTouch\id_rsa"
-t specifies encryption type 'RSA'
-b use 8192-bit key
-N explicitly specifies empty keyphrase
I can confirm that user10613465's answer worked in my case.
ssh-keygen -t rsa -N "" -f "%LOCALAPPDATA%\Xamarin\MonoTouch\id_rsa"
In my case I had the correct versions of Windows, Visual Studio and Xamarin.
The system passed until tests number 8 and 9 described here:
link from official Xamarin on MS Docs
I know it's manner to comment on his asnwer, but I don't have the privillege yet (using work email's StackOverflow account)
It's indeed caused by a bug in Xamarin. The solution suggested by user10613465
does not work with recent versions of Xamarin (at least not for me), however I've found a workaround.
Background
Feel free to skip this section* Xamarin generates a pair of SSH keys
stored in in %LOCALAPPDATA%\AppData\Local\Xamarin\MonoTouch. SSH key files comes
in multiple flavors. One is RSA, another is OPENSSH. The flavor can be
found by inspecting the first line in the key file. The problem here
is Xamarin generates OPENSSH keys; but can't read them.
In recent versions of Xamarin the private key is encrypted and the
passphrase itself is encrypted and stored in a file named
passphrase.key. If you attempt to erase the files and generate a new
keyset of the correct flavor as suggested, Xamarin will reject the
keys a generate a new set it doesn't understand.
Stategy
Feel free to skip this one too. My research suggests you can't
convert an OPENSSH key to a RSA key. As far as I can see, Xamarin does
not use any external program to generate the key set, so replacing/redirecting
is not a viable solution.
The solution I found is to generate a new keyset of the supported
flavor, with the same passphrase and leaving passphrase.key in place. Getting the passphrase is the tricky part. I've used VS to debug another instance of VS to obtain it.
Procedure
I assume you already have attempted ot pair and have a defective key
pair (id_rsa, id_rsa.pub and passphrase.key)
Fire up Visual Studio (VS), open some project. We'll call this
instance A of VS.
Select Tools -> IOS -> Pair to mac.
Enter IP address or name of your Mac, but DO NOT enter name and
password yet.
Start another instance of VS. We call this instance B.
In instance B, select Debug -> Options
In Debuging -> Options, deselect "Enable Just my code", Click OK.
Select Debug, Attach to Process.
Select the Instance A of VS. The process is called devenv.exe.
In instance B, Select Debug -> Windows -> Breakpoints
In the breakpoints window, click on New -> Function breakpoint. Select
Renci.SshNet.PrivateKeyFile.Open.
Now, in instance A, enter name and password and click OK. The
breakpoint is now hit by instance A so it freeze.
In instance B you should see some assembler code. The code itself is
not important; but we should be able to see the arguments to the
method. Open the local variable window by clicking through Debug ->
Windows -> Locals
One variable is the passphrase. It looks like a uuid. Copy it to the
clipboard and store it somewhere convenient.
Resume execution, close both VS instances.
Enter C:\Users\mk\AppData\Local\Xamarin\MonoTouch
Verify you can connect to your mac using the key and the passphrase we
just recovered:
ssh -i id_rsa mymac
Move the old key out of the way:
mkdir old
move id_rsa old
move id_rsa.pub old
Generate a new set of keys, use the same passphrase.
ssh-keygen -t rsa -N "" -f "%LOCALAPPDATA%\Xamarin\MonoTouch\id_rsa"
Verify the header in id_rsa looks like this
----BEGIN RSA PRIVATE KEY-----
and not like this
-----BEGIN OPENSSH PRIVATE KEY-----
If it doesn't, you need to use another ssh-keygen. Perhaps putty can
help you there.
Log in to the mac computer. Edit .ssh/authorized_keys and remove the
old key. (The one you find in
"%LOCALAPPDATA%\Xamarin\MonoTouch\old\id_rsa.pub"
Add the new public from "%LOCALAPPDATA%\Xamarin\MonoTouch\id_rsa.pub"
This solved the problem for me