Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SSH Key Authentication Fails with macOS Ventura #1003

Closed
mauroa opened this issue Sep 15, 2022 · 13 comments
Closed

SSH Key Authentication Fails with macOS Ventura #1003

mauroa opened this issue Sep 15, 2022 · 13 comments
Milestone

Comments

@mauroa
Copy link

mauroa commented Sep 15, 2022

When I try to authenticate with an RSA SSH key from Windows into macOS Ventura, I get a Permission denied (publickey). error. However, If I run the same code against macOS Monterrey, it works correctly.
I'm attaching a repro solution so you can give it a try.

Repro Steps:

  • Pre-requisites:

    • Copy the content of the testKey.pub file (included in the test project) into /Users/.<userName>/ssh/authorized_keys in the Mac
  • Assign the corresponding values to the host and userName variables in the Program.cs file of the attached project

  • Build and run the console app

Expected Results: the console should connect to the host with the given username and included private key (testKey)

Current Results: the console doesn't connect and show a Permission denied (publickey). error instead

Notes:

  • The attached SSH key pair has been generated using this command: ssh-keygen -b 2048 -t rsa -m PEM -f "<filePath/>" -q -N "<passPhrase/>"

  • If I try to SSH connect to macOS Ventura with a Windows command prompt using the same key, it works correctly

SshNetVenturaRepro.zip

@mauroa
Copy link
Author

mauroa commented Oct 23, 2022

Update: I tried debugging SSH.NET and I'm seeing that the server returns an SSH_MSG_USERAUTH_FAILURE. However, I'm not seeing any log in sshd in the Mac. On the other hand, If I use the same code sample but using password authentication, it works correctly. What is strange is that from a Windows command prompt and doing ssh -i "C:\Users\<user>\Downloads\SshNetVenturaRepro\SshNetVenturaRepro\testKey" user@ipaddress it works correctly, so it looks like the key format is supported but something in the SSH.NET code is conflicting with the server

@mauroa
Copy link
Author

mauroa commented Oct 23, 2022

Update 2: I tried generating a key pair with another key format (ssh-keygen -t ecdsa -b 521), and it worked. So it looks like the issue is with RSA keys, however using the same RSA keys from a Windows command prompt works, so I don't think the issue is on the server side

@mauroa
Copy link
Author

mauroa commented Oct 24, 2022

Update 3: Looks like the latest SSH.NET public version doesn't include support for ECDSA :/, but the latest develop does

@vallgrenerik
Copy link

@mauroa Do you know if this is related to this:
image?
Is this being worked on? 😊

@giccifelipe
Copy link

I'm having the same issue as you @vallgrenerik, can't get the pair to work. Everything is with the latest version, both windows vs and mac/xcode.

I can't find the solution anywhere 😞

@vallgrenerik
Copy link

@giccifelipe
Found this Temporary fix until VS gets updated:
https://stackoverflow.com/questions/74215881/vs-2022-wont-connect-with-mac-after-ventura-upgrade
Remember to reboot Mac and restart VS on your windows machine 👍

@giccifelipe
Copy link

@vallgrenerik
not sure I did it right:

  1. add those lines at the bottom of the sshd_config (located at the 'Macintosh HD'/etc/ssh/... folder):
    HostkeyAlgorithms +ssh-rsa
    PubkeyAcceptedAlgorithms +ssh-rsa
    image
  2. reboot mac
  3. reboot vs

still getting the screen:
image

Any thoughts?

@giccifelipe
Copy link

giccifelipe commented Oct 31, 2022

@vallgrenerik I've managed to get working after doing a full reboot, shutting down both OSs. thanks.

@mauroa
Copy link
Author

mauroa commented Oct 31, 2022

Just to confirm everyone concerns, the Pair To Mac error is directly related to this issue. However, VS is releasing a fix for it sooner than later. Please follow this ticket in order to keep updated: https://developercommunity.visualstudio.com/t/Impossible-to-connect-to-Remote-Mac-Host/10163760

@phu-mai-jemmic
Copy link

This solution works for me
0. (Backup ~/.ssh/ folder)

  1. If your ssh config and private/public keys are in /etc/ssh/ before upgrading the MacOS
  • copy ssh_config to ~/.ssh/config
  • copy all private/public keys to ~/.ssh/
  1. Adding the following lines at the end of ~/.ssh/config
HostkeyAlgorithms +ssh-rsa
PubkeyAcceptedAlgorithms +ssh-rsa
KexAlgorithms +diffie-hellman-group1-sha1

@Pratap22
Copy link

Pratap22 commented Jul 7, 2023

As the solution mentioned by @phu-mai-jemmic and @giccifelipe works for rsa keys, but do you know how to fix it for ecdsa keys?

@WojciechNagorski
Copy link
Collaborator

Fixed by #1177 and #1180

@WojciechNagorski
Copy link
Collaborator

Version 2023.0.0 has been published https://www.nuget.org/packages/SSH.NET/2023.0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants