我无法通过Visual Studio 2015使用Xamarin Mac代理连接到Mac。

25
我正在继续使用Xamarin进行开发。
我正在使用Portable Class Libraries (PCL)开发一个Xamarin Forms应用程序。
我已经在Android上编译和调试了我的应用程序,但现在我想在iOS上运行应用程序以在该平台上进行测试。
我在PC和Mac之间的连接出现了问题。
我有一台安装有Visual Studio Community 2015和Xamarin工具的Windows 8.1 PC。
在我的Mac Mini上,我安装了OS X(v10.11.3)、XCode(v7.2)和Xamarin Studio,并使用了我的Xamarin帐户登录。
在这两台机器上,我都安装了相同版本的Xamarin。
我遵循了Xamarin walkthrough
在Visual Studio中,我打开了Xamarin Mac Agent。它找到了我的Mac Mini。然后它要求我输入Mac凭据(用户名和密码)。

enter image description here

登录功能目前可用。

enter image description here

然后,在解决方案中,我将iOS项目设置为启动项目。我清理解决方案,再次构建并开始编译/调试过程(F5)。
在此时,输出检索到一条消息:
1>正在连接到Mac服务器Macs-Mac-mini.local... 1>C:\Program Files (x86)\MSBuild\Xamarin\iOS\Xamarin.iOS.Windows.After.targets(54,5): 警告:无法使用现有的ssh密钥进行用户身份验证 1>C:\Program Files (x86)\MSBuild\Xamarin\iOS\Xamarin.iOS.Windows.After.targets(54,5): 错误:无法连接到Address='Macs-Mac-mini.local',User='macmini'
我使用Putty(SSH客户端)检查了我的用户名/密码是否能够连接到Mac,并且成功了。
每当我使用Xamarin Mac Agent时,Visual Studio都会向/Users/macmini2/.ssh/authorized_keys文件(Mac机器)添加一个新的密钥条目(它会添加相同的重复内容)。
我看到问题可能与ssh密钥有关。我为什么会出现这个问题?我做错了什么?

我测试过的一件事是直接在Mac上用Xamarin Studio打开Xamarin项目,构建并运行模拟器。它可以正常工作。

我看到了其他类似的问题, 但我认为它没有同样的问题。

编辑:

当我尝试编译/调试时出现错误的更具体信息:

Could not authenticate the user using the existing ssh keys
Xamarin.Messaging.VisualStudio.MessagingAuthenticationException: Could not authenticate the user using the existing ssh keys ---> Renci.SshNet.Common.SshAuthenticationException: Permission denied (publickey).
   en Renci.SshNet.ClientAuthentication.Authenticate(IConnectionInfoInternal connectionInfo, ISession session)
   en Renci.SshNet.ConnectionInfo.Authenticate(ISession session)
   en Renci.SshNet.Session.Connect()
   en Renci.SshNet.BaseClient.Connect()
   en Xamarin.Messaging.VisualStudio.MessagingService.<ConnectAsync>d__70.MoveNext()
   --- Fin del seguimiento de la pila de la excepción interna ---

编辑2:

我已经修改了 Xamarin故障排除页面,特别是它说“无法使用SSH密钥进行身份验证。请先尝试使用凭据登录。”

我已运行:

chmod og-w "$HOME"
grep sshd /var/log/system.log > "$HOME/Desktop/sshd.log"
cd Desktop
cat sshd.log

而文件的内容是:

Apr 18 09:23:28 Macs-Mac-mini sshd[769]: Authentication refused: bad ownership or modes for directory /Users/macmini2/.ssh
Apr 18 09:25:27 Macs-Mac-mini com.apple.xpc.launchd[1] (com.openssh.sshd.EE9A94ED-????-....-????-77254934B300[769]): Service exited with abnormal code: 1
Apr 18 09:59:39 Macs-Mac-mini sshd[1036]: Accepted keyboard-interactive/pam for macmini2 from 192.168.54.14 port 60413 ssh2
Apr 18 09:59:39 Macs-Mac-mini sshd: macmini2 [priv][1036]: USER_PROCESS: 1040 ttys000

但现在我不知道该怎么做才能解决它。

这是SSH连接的问题。你在Mac上开启了远程登录吗?你尝试过使用SSH连接Mac和其他设备吗? - Xin Meng
@XinMeng 是的,我也这么认为。问题在于SSH连接。我可以使用Putty(使用用户名和密码)从Windows连接到Mac。登录是有效的。但是我没有尝试通过生成的Xamarin Mac代理程序的密钥建立ssh连接。我不知道在Putty中使用哪些SSH密钥来进行测试。 - stivex
在我的情况下:“Xcode未安装。请安装它并尝试重新连接或选择其他服务器进行连接。”但当然,已经安装了Xcode(9.0 beta 6)。无法提问(您已达到问题限制:()。有人,请帮忙。 - MD TAREQ HASSAN
15个回答

36
你需要尝试删除

标签后面的所有内容。
%localappdata%\Xamarin\MonoTouch

它对我有帮助,我今天也遇到了同样(或相似)的问题。


谢谢您的建议!我已经尝试了您的建议,但是(对我来说)它不起作用。我已经删除了您指定的Windows目录中的id_rsa文件,并且还删除了我的Mac中的authorized_keys文件。在公钥文件的末尾出现了macmini2@Macs-Mac-mini.local,我不确定“.local”是否是正确的格式用户/ur。 - stivex
谢谢,你救了我的一天。 - eakgul
非常感谢!我按照您的建议操作,成功解决了类似的问题。 - Hao
我没有删除,而是将我的私钥和公钥添加到了那个文件夹中。这些密钥已经添加到了主机(Mac)上。 - Dalton Lima

17

我已经找到了解决方案,以下是我的步骤:

  1. 在Windows系统中:删除 "%localappdata%\Xamarin\MonoTouch" 文件夹内的所有内容。
  2. 在Mac终端中:删除 authorized_keys 文件(例如,在我的情况下,使用"rm /Users/macmini2/.ssh/authorized_keys" 命令)。
  3. 在Mac终端中:运行命令 "chmod g-w /Users/macmini2/"。
  4. 在Mac终端中:运行命令 "chmod 700 /Users/macmini2/.ssh/"。
  5. 在Mac终端中:创建一个空文件:/Users/macmini2/.ssh/authorized_keys (例如,使用vim编辑器)。
  6. 在Mac终端中:运行命令 "chmod 600 /Users/macmini2/.ssh/authorized_keys"。
  7. 在Visual Studio中:使用 Xamarin Mac Agent 登录。
  8. 在Visual Studio中:使用 [Debug] - [iPhoneSimulator] - [iPhone 5 iOS 8.1] 运行应用程序。
  9. 最后,在Mac电脑上模拟器成功运行。

这个链接帮助了我解决问题。


5
关于第五点 - 因为您在终端中,可以使用命令"touch /Users/macmini2/.ssh/authorized_keys"创建文件。 - Bartosz Strutyński
我的设置可能有问题,因为每次Xamarin或MacOSX更新后,我都需要重复这些步骤。所以感谢这些说明!我用它们制作了一个批处理文件,现在它可以完美地工作 :) - Bartosz Strutyński
1
可悲的是,这些步骤对我完全没有用。问题仍然存在。我按照故障排除清单中的每一项和此处列出的每一项都尝试了,但无济于事。:( - John Tamburo
@JohnTamburo 如果您提供了一些关于您的问题的线索,我们可以帮助您。 - stivex
2
这个命令对我有效,使用权限_chmod -R 755 /Users/test/.ssh_。连接后,您可以将目录...../ssh重置回700。 - Ramesh Chand
显示剩余3条评论

7
Xamarin有一份疑难解答页面,主要关注SSH问题:

连接疑难解答

具体来说,重点是以下两个方面:

日志文件位置

Mac – ~/Library/Logs/Xamarin-[MAJOR.MINOR]
Windows – %LOCALAPPDATA%\Xamarin\Logs

在Visual Studio中,可以通过浏览到“帮助> Xamarin > Zip Logs”来定位日志文件。

"使用SSH密钥无法进行身份验证。请先尝试使用凭据登录"

已知原因:

SSH security restriction – This message most often means that one of the files or directories in the fully qualified path of $HOME/.ssh/authorized_keys on the Mac has write permissions enabled for other or group members. Common fix: Run chmod og-w "$HOME" in a Terminal command prompt on the Mac. For details about which particular file or directory is causing the problem, run grep sshd /var/log/system.log > "$HOME/Desktop/sshd.log" in Terminal, and then open the sshd.log file from your Desktop and look for "Authentication refused: bad ownership or modes".

此外,还有这个部分,虽然与您看到的错误不直接相关,但详细介绍了SSH配置和诊断:

"无法连接到MacBuildHost.local。请重试。"

报告的原因:

Bug – A few users have seen this error message when attempting to log in to the build host using an Active Directory domain user account.

Bug – Some users have seen this error when attempting to connect to the build host by double-clicking the name of the Mac in the connection dialog. Possible workaround: Manually add the Mac using the IP address.

Bug #35971 – Some users have run across this error when using a wireless network connection between the Mac build host and Windows. Possible workaround: Move both computers to a wired network connection.

Bug #36642 – On Xamarin 4.0, this message will appear anytime the $HOME/.bashrc file on the Mac contains an error. (Starting with Xamarin 4.1, errors in the .bashrc file will no longer affect the connection process.) Workaround: Move the .bashrc file to a backup location (or delete it if you know you don't need it).

Limitation – This error can appear if the Mac build host is connected to a router that has no access to the internet (or if the Mac is using a DNS server that times out when asked for the reverse-DNS lookup of the Windows computer). Visual Studio will take roughly 30 seconds to retrieve the SSH fingerprint and eventually fail to connect.

Possible workaround: Add "UseDNS no" to the sshd_config file. Be sure to read about this SSH setting before changing it. See for example http://unix.stackexchange.com/questions/56941/what-is-the-point-of-sshd-usedns-option.

The following steps describe one way to change the setting. You will need to be logged in to an administrator account on the Mac to complete the steps.

    Confirm the location of the sshd_config file by running ls /etc/ssh/sshd_config and ls /etc/sshd_config in a Terminal command prompt. For all of the remaining steps, be sure to use the location that does not return "No such file or directory".

    Run cp /etc/ssh/sshd_config "$HOME/Desktop/" in Terminal to copy the file to your desktop.

    Open the file from your Desktop in a text editor. For example you can run open -a TextEdit "$HOME/Desktop/sshd_config" in Terminal.

    Add the following line at the bottom of the file:

    UseDNS no

    Remove any lines that say UseDNS yes to make sure the new setting takes effect.

    Save the file.

    Run sudo cp "$HOME/Desktop/sshd_config" /etc/ssh/sshd_config in Terminal to copy the edited file back into place. Enter your password if prompted.

    Disable and re-enable Remote Login under System Preferences > Sharing > Remote Login to restart the SSH server.

我之前已经看过这篇Xamarin文章,但我又重新复习了一遍。我按照“无法使用SSH密钥进行身份验证。请先尝试使用凭据登录”的步骤进行操作。我在sshd.log文件中得到了与他们所说相同的错误。但现在我不知道该怎么做才能解决它。 - stivex
我在故障排除中提到的 Mac 上的终端中运行了 chmod og-w "$HOME" 命令。 - lolelo

5

我刚刚解决了这个问题!

当您遇到以下问题时,需要连接Visual Studio Xamarin项目并在Mac上模拟:

无法连接到computername.local,请稍后再试。

下一步需要做的事情:

  1. 按照Xamarin社区关于Mac连接的解决方案进行操作。如果一切正常,您将成功连接,否则...
  2. 在Mac上安装XAMARIN STUDIO。安装完成后启动XAMARIN studio,创建您自己的应用程序并使用模拟器运行。
  3. 关闭应用程序,然后再次从Windows计算机尝试连接。此时,您将进行同步,就完成了。

问题解决了!希望这对某人有所帮助。


你有 Xamarin 社区解决方案的链接吗? - Pellet

4
对我来说,下面的解决方案很有帮助: 1)在Windows上打开Visual Studio: 工具=>选项=>Xamarin=>其他,然后点击“立即检查”。
2)在Mac上打开Xamarin Studio Community (https://www.xamarin.com/download) Xamarin Studio Community=>检查更新...(并下载最新的版本)
更新后一切正常。

哇!就这样了!谢谢! - PSsam

3

我尝试了这里提到的一些解决方案,但都没有成功。

然而(虽然不是最理想的)如果我以管理员模式运行Visual Studio,则可以成功连接。这可能是一种解决方法,直到找到更好的解决方案。


这应该是一条评论,而不是一个答案。 - Alex Shesterov
2
声望不足50,因此我无法发表评论。 - Aazarus

2

这不是完美的解决方案,但在我的情况下取得了成功

你的Mac账户不应包含任何特殊字符- 这是从Windows连接到Mac的限制

company-mac1 --- 错误

comapanymac1 --- 正确


1

1
忽略Visual Studio向导显示的代理。有关Mac计算机名称,VS无法理解。

我执行了“添加Mac”,使用了IP地址,然后它连接成功了。那真是让人恼火。


1

就我所知,我刚刚通过检查日志解决了这个问题,如上所述和 Xamarin 故障排除文档中提到的。原来是 iOS 版本不匹配。一旦我更新了 Mac 版本,它就可以正常工作了。

enter image description here


这对我非常有效。我必须前往“工具”->“选项”->“Xamarin”到iOS设置,以启动Mac代理并重新连接到Mac,但最终成功了。我不需要从Xamarin/Monotouch目录中删除任何内容。很容易忘记更新Mac端(我必须在那里使用Xamarin Studio来完成它,因为Xamarin Installer似乎并不总是能够更新该部分)。 - bcr

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接