与 mac 配对错误无法执行 'grep "ssh-rsa ...."

Ste*_*eve 3 xamarin.ios xamarin

我尝试将我的 Macbook 与 Visual Studio 2022 配对,但输入凭据后,我在 gui 对话框中收到以下错误:“尝试使用 SSH 密钥与‘192.168.178.27:22’建立 SSH 连接时出错”

检查日志时出现以下错误:

Xamarin.Messaging.Ssh.SshCommandRunner Warning: 0 : Failed to execute 'grep "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDRpqma2f+6ghu6P2/Jxx2Aj6+4kY/1tFpkvM1CdlscbvESZFsYakl90P9YvXQhHTXhK6QUHgj4E9s+Ze4PxmXSfYd7b3imWpbSOIqWrlC4rfMn31F3EyJ60Cpc9DO15MtiVS9ctTWBKXzRU8NbUlek8LppEID5Xv0nEroryNHEzINXSvyhmTyUHAOklTjm3NVpqLrbGbFw9d6+F8pVskWtYyfFVl9PuW0EhbVox9inWGQIzbCMdVzjGb5M3ua/taNtTz8W6hsUQm8SB7UANR36klHUIWYmSQ5ZgyIkCZ7x6pNyRL2sr6UtFAfsp+vnGsIzakKHvZDXz7uBnRl6/Z7f steve@Stefans-MacBook-Pro.local" "/Users/steve/.ssh/authorized_keys"': ExitStatus = 1: 10.25.2022 22:41:25Z
  DateTime=2022-10-25T22:41:25.3448659Z: 10.25.2022 22:41:25Z
Run Code Online (Sandbox Code Playgroud)

完整日志:

Xamarin.Messaging.Integration.State.ServerStateContext Error: 0 : !An error occurred while trying to establish an SSH connection with SSH keys to '192.168.178.27:22': 10.25.2022 22:36:36Z
  DateTime=2022-10-25T22:36:36.5456548Z: 10.25.2022 22:36:36Z
Xamarin.Messaging.Integration.State.ServerStateContext Information: 0 : Server State transition from DisconnectedState to ConfiguringState on macbook.lan (192.168.178.27): 10.25.2022 22:41:20Z
  DateTime=2022-10-25T22:41:20.2772963Z: 10.25.2022 22:41:20Z
Xamarin.Messaging.Integration.State.ServerStateContext Information: 0 : Checking host configuration for connecting to 'macbook.lan'...: 10.25.2022 22:41:20Z
  DateTime=2022-10-25T22:41:20.3057061Z: 10.25.2022 22:41:20Z
Xamarin.Messaging.Integration.State.ServerStateContext Information: 0 : !Checking host configuration for connecting to 'macbook.lan'...: 10.25.2022 22:41:20Z
  DateTime=2022-10-25T22:41:20.3057061Z: 10.25.2022 22:41:20Z
Xamarin.Messaging.Integration.State.ServerStateContext Information: 0 : Checking SSH configuration...: 10.25.2022 22:41:20Z
  DateTime=2022-10-25T22:41:20.3487326Z: 10.25.2022 22:41:20Z
Xamarin.Messaging.Integration.State.ServerStateContext Information: 0 : !Checking SSH configuration...: 10.25.2022 22:41:20Z
  DateTime=2022-10-25T22:41:20.3487326Z: 10.25.2022 22:41:20Z
Xamarin.Messaging.Ssh.SshCommandRunner Warning: 0 : Failed to execute 'grep "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDRpqma2f+6ghu6P2/Jxx2Aj6+4kY/1tFpkvM1CdlscbvESZFsYakl90P9YvXQhHTXhK6QUHgj4E9s+Ze4PxmXSfYd7b3imWpbSOIqWrlC4rfMn31F3EyJ60Cpc9DO15MtiVS9ctTWBKXzRU8NbUlek8LppEID5Xv0nEroryNHEzINXSvyhmTyUHAOklTjm3NVpqLrbGbFw9d6+F8pVskWtYyfFVl9PuW0EhbVox9inWGQIzbCMdVzjGb5M3ua/taNtTz8W6hsUQm8SB7UANR36klHUIWYmSQ5ZgyIkCZ7x6pNyRL2sr6UtFAfsp+vnGsIzakKHvZDXz7uBnRl6/Z7f steve@Stefans-MacBook-Pro.local" "/Users/steve/.ssh/authorized_keys"': ExitStatus = 1: 10.25.2022 22:41:25Z
  DateTime=2022-10-25T22:41:25.3448659Z: 10.25.2022 22:41:25Z
Xamarin.Messaging.Integration.State.ServerStateContext Information: 0 : Checking host configuration for connecting to 'macbook.lan'...: 10.25.2022 22:41:25Z
  DateTime=2022-10-25T22:41:25.4160488Z: 10.25.2022 22:41:25Z
Xamarin.Messaging.Integration.State.ServerStateContext Information: 0 : !Checking host configuration for connecting to 'macbook.lan'...: 10.25.2022 22:41:25Z
  DateTime=2022-10-25T22:41:25.4160488Z: 10.25.2022 22:41:25Z
Xamarin.Messaging.Integration.State.ServerStateContext Information: 0 : Server State transition from ConfiguringState to DisconnectingState on macbook.lan (192.168.178.27): 10.25.2022 22:41:25Z
  DateTime=2022-10-25T22:41:25.4275618Z: 10.25.2022 22:41:25Z
Xamarin.Messaging.Integration.State.ServerStateContext Information: 0 : Starting disconnection from macbook.lan...: 10.25.2022 22:41:25Z
  DateTime=2022-10-25T22:41:25.4315733Z: 10.25.2022 22:41:25Z
Xamarin.Messaging.Integration.State.ServerStateContext Information: 0 : !Starting disconnection from macbook.lan...: 10.25.2022 22:41:25Z
  DateTime=2022-10-25T22:41:25.4315733Z: 10.25.2022 22:41:25Z
Xamarin.Messaging.Integration.State.ServerStateContext Information: 0 : Server State transition from DisconnectingState to DisconnectedState on macbook.lan (192.168.178.27): 10.25.2022 22:41:25Z
  DateTime=2022-10-25T22:41:25.4591158Z: 10.25.2022 22:41:25Z
Xamarin.Messaging.Integration.State.ServerStateContext Information: 0 : Starting disconnection from macbook.lan...: 10.25.2022 22:41:25Z
  DateTime=2022-10-25T22:41:25.4631158Z: 10.25.2022 22:41:25Z
Xamarin.Messaging.Integration.State.ServerStateContext Information: 0 : !Starting disconnection from macbook.lan...: 10.25.2022 22:41:25Z
  DateTime=2022-10-25T22:41:25.4631158Z: 10.25.2022 22:41:25Z
Xamarin.Messaging.Integration.State.ServerStateContext Information: 0 : The connection to 'macbook.lan' has been finished: 10.25.2022 22:41:25Z
  DateTime=2022-10-25T22:41:25.4641170Z: 10.25.2022 22:41:25Z
Xamarin.Messaging.Integration.State.ServerStateContext Information: 0 : !The connection to 'macbook.lan' has been finished: 10.25.2022 22:41:25Z
  DateTime=2022-10-25T22:41:25.4641170Z: 10.25.2022 22:41:25Z
Xamarin.Messaging.Integration.State.ServerStateContext Error: 0 : An error occurred while trying to establish an SSH connection with SSH keys to '192.168.178.27:22'
Xamarin.Messaging.Integration.MessagingConfigurationException: An error occurred while trying to establish an SSH connection with SSH keys to '192.168.178.27:22' ---> System.IO.FileNotFoundException: Could not find file 'C:\Users\Stefan\AppData\Local\Xamarin\MonoTouch\id_rsa'.
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
   at Renci.SshNet.PrivateKeyFile..ctor(String fileName, String passPhrase)
   at Xamarin.Messaging.Ssh.MessagingAuthenticationMethod.InitializePrivateKeyAuthentication(String username, ISshInformationProvider sshInformationProvider) in D:\a\_work\1\s\src\Xamarin.Messaging.Ssh\MessagingAuthenticationMethod.cs:line 84
   at Xamarin.Messaging.Integration.State.ConfiguringState.<GetSshConnectionAsync>d__17.MoveNext() in D:\a\_work\1\s\src\Xamarin.Messaging.Integration\State\ConfiguringState.cs:line 193
   --- End of inner exception stack trace ---
   at Xamarin.Messaging.Integration.State.ConfiguringState.<GetSshConnectionAsync>d__17.MoveNext() in D:\a\_work\1\s\src\Xamarin.Messaging.Integration\State\ConfiguringState.cs:line 224
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Xamarin.Messaging.Integration.State.ConfiguringState.<GetSshConnectionAsync>d__15.MoveNext() in D:\a\_work\1\s\src\Xamarin.Messaging.Integration\State\ConfiguringState.cs:line 127
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Xamarin.Messaging.Integration.State.ConfiguringState.<OnExecutingAsync>d__14.MoveNext() in D:\a\_work\1\s\src\Xamarin.Messaging.Integration\State\ConfiguringState.cs:line 70: 10.25.2022 22:41:25Z
  DateTime=2022-10-25T22:41:25.4907201Z: 10.25.2022 22:41:25Z
Xamarin.Messaging.Integration.State.ServerStateContext Error: 0 : !An error occurred while trying to establish an SSH connection with SSH keys to '192.168.178.27:22': 10.25.2022 22:41:25Z
  DateTime=2022-10-25T22:41:25.4917191Z: 10.25.2022 22:41:25Z
System.Net.Mqtt.Sdk.ClientPacketListener Error: 0 : Client - An error occurred while listening and dispatching packets
System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
   at System.Net.Sockets.Socket.EndReceive(IAsyncResult asyncResult)
   at System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult)
   --- End of inner exception stack trace ---
   at System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult)
   at System.Threading.Tasks.TaskFactory`1.FromAsyncTrimPromise`1.Complete(TInstance thisRef, Func`3 endMethod, IAsyncResult asyncResult, Boolean requiresSynchronization): 10.25.2022 22:45:28Z
  DateTime=2022-10-25T22:45:28.6158613Z: 10.25.2022 22:45:28Z
System.Net.Mqtt.Sdk.ClientPacketListener Error: 0 : Client - An error occurred while listening and dispatching packets
System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
   at System.Net.Sockets.Socket.EndReceive(IAsyncResult asyncResult)
   at System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult)
   --- End of inner exception stack trace ---
   at System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult)
   at System.Threading.Tasks.TaskFactory`1.FromAsyncTrimPromise`1.Complete(TInstance thisRef, Func`3 endMethod, IAsyncResult asyncResult, Boolean requiresSynchronization): 10.25.2022 22:45:28Z
  DateTime=2022-10-25T22:45:28.6168613Z: 10.25.2022 22:45:28Z
System.Net.Mqtt.Sdk.MqttClientImpl Error: 0 : System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
   at System.Net.Sockets.Socket.EndReceive(IAsyncResult asyncResult)
   at System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult)
   --- End of inner exception stack trace ---
   at System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult)
   at System.Threading.Tasks.TaskFactory`1.FromAsyncTrimPromise`1.Complete(TInstance thisRef, Func`3 endMethod, IAsyncResult asyncResult, Boolean requiresSynchronization): 10.25.2022 22:45:28Z
  DateTime=2022-10-25T22:45:28.6188610Z: 10.25.2022 22:45:28Z
Xamarin.Messaging.Ssh.MessagingService Error: 0 : An error occurred on the underlying client while executing an operation. Details: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.: 10.25.2022 22:45:28Z
  DateTime=2022-10-25T22:45:28.6413821Z: 10.25.2022 22:45:28Z
Run Code Online (Sandbox Code Playgroud)

关于丢失文件的例外情况具有误导性。首先它不存在,但如果您在连接过程中查看该文件夹,它会与其他文件一起创建,当失败时,它会再次被删除。所以我假设这是一个不同的错误。

并且 ssh 登录到机器,一切正常。我可以通过 ssh 进入它,如果您启用详细登录,则其他命令以及 scp 都可以正常执行。

有没有人遇到过这个问题并有解决方案?

视觉工作室 2022

OSX Ventura 与 XCode 14.0.1 和 Visual Studio 17.3.8 (build5)

o.k*_*k.w 6

事实证明,对于我遇到的类似问题,根本原因是由于Ventura而与SSH相关,与VS或防火墙无关。

这篇文章描述了问题和解决方案。

macOS Ventura 附带 OpenSSH_9.0p1,默认情况下禁用使用 SHA1 算法的 RSA 签名。如果您阅读发行说明,您可以找到重新启用它的方法,直到 Microsoft 发布 Xamarin 配对的 SSH 实现的更新。

可能不兼容的更改

此版本默认禁用使用 SHA-1 哈希算法的 RSA 签名。进行此更改是因为 SHA-1 哈希算法在密码学上已被破坏,并且可能会造成 <USD$50K 的选择前缀哈希冲突

对于大多数用户来说,此更改应该是不可见的,并且无需替换 ssh-rsa 密钥。OpenSSH 自 7.2 版起就支持 RFC8332 RSA/SHA-256/512 签名,现有的 ssh-rsa 密钥将在可能的情况下自动使用更强的算法。

这篇文章介绍了如何在不重新启动计算机的情况下重新启动 SSHD。

我按照这些步骤操作,不再遇到与 SSH 相关的连接/配对问题。