Bug 37600 - [XVS 4.0] "The application UnifiedSingleViewIphone1 needs to be rebuilt due to an inconsistency between the connected Mac and the local app" due to warning "Could not authenticate the user using the existing ssh keys" during build
Summary: [XVS 4.0] "The application UnifiedSingleViewIphone1 needs to be rebuilt due t...
Status: VERIFIED ANSWERED
Alias: None
Product: Visual Studio Extensions
Classification: Xamarin
Component: iOS ()
Version: 4.0.0 (C6)
Hardware: PC Windows
: --- major
Target Milestone: 4.0.2 (C6SR2)
Assignee: Bugzilla
URL:
: 36059 37251 ()
Depends on:
Blocks:
 
Reported: 2016-01-12 04:28 UTC by Brendan Zagaeski (Xamarin Team, assistant)
Modified: 2016-03-07 15:42 UTC (History)
6 users (show)

Tags: BZRC6S1_C5SR5S1
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
VERIFIED ANSWERED

Description Brendan Zagaeski (Xamarin Team, assistant) 2016-01-12 04:28:59 UTC
[XVS 4.0] "The application UnifiedSingleViewIphone1 needs to be rebuilt due to an inconsistency between the connected Mac and the local app" due to warning "Could not authenticate the user using the existing ssh keys" during build



This is a new bug to separate out one particular cause of the "inconsistency" error that can arise when attempting to deploy to an iOS device or simulator.




## Example "main" error message

> The application UnifiedSingleViewIphone1 needs to be rebuilt due to an
> inconsistency between the connected Mac and the local app. Please rebuild the
> application and try




(Note that this message is _correct_ if either (a) you have old files on the Mac build host that were created before the update to Xamarin 4 or (b) you have new build files on the Windows PC that were built while _explicitly disconnected_ from the Mac build host. In either of those cases, the steps under "expected to stop the problem" from Bug 36059, Comment 0 should successfully stop the problem.)


See also Bug 36059, Comment 0 for a little additional description of the "meaning" of this "main" error message.



Unfortunately, this "main" error message is fairly generic. It can happen for several different reasons (some of them _correct_ as mentioned above). This new bug report is intended to track one specific cause of this error message where both of the following build warnings also appear in the Error List (and in the Build Output).




## Example of the warning messages that are the "real" problem for this particular bug report

> C:\Program Files
> (x86)\MSBuild\Xamarin\iOS\Xamarin.iOS.Windows.After.targets(54,5):
> warning : Could not authenticate the user using the existing ssh keys

> C:\Program Files
> (x86)\MSBuild\Xamarin\iOS\Xamarin.iOS.Windows.After.targets(54,5):
> warning VSXRunBuildLocally: The project App1 was built while
> disconnected from a Mac agent, so only the main assembly was compiled.
> Connect to a Xamarin Mac build agent to build the full application.




## Possible workarounds

There have been some reports that creating a brand new project or explicitly "forgetting" the build host and then reconnecting (re-entering your SSH password) might sometimes help, but it seems those workarounds are temporary at best.


In contrast, downgrading temporarily to Xamarin 3 [1] stops the problem more reliably. (This downgrade unfortunately comes with the trade-off of going back to the older HTTP-based build host that had several different unrelated bugs. Those old bugs can cause trouble for certain development workflows.)

[1] https://store.xamarin.com/account/my/subscription/downloads#xamarin3
Comment 1 Brendan Zagaeski (Xamarin Team, assistant) 2016-01-12 04:45:12 UTC
*** Bug 36059 has been marked as a duplicate of this bug. ***
Comment 2 Brendan Zagaeski (Xamarin Team, assistant) 2016-01-12 05:31:42 UTC
## Alternate possible workaround: command line builds

Based on reports from a few users who have tried it, it seems that the following steps have been a successful workaround in some cases. (These steps will have the best chance of success with "Cycle 6 – Service Release 1", currently available on the Alpha updater channel.)


1. Build the iOS app project on the command line using a command similar to the following:

> C:\> msbuild /t:Build /p:Configuration=Debug /p:Platform=iPhoneSimulator /p:ServerAddress=<mac ip address> /p:ServerUser=<build host username>  /p:ServerPassword=<build host password> UnifiedSingleViewIphone1.sln

(See also http://developer.xamarin.com/guides/ios/getting_started/installation/windows/xamarin-mac-agent/#Command_Line_Support)


2. Open the solution in Visual Studio.


3. Make sure not to make any changes (so the build signature will not change when VS recomputes it).


4. Deploy and debug the project on the iOS simulator.
Comment 5 Brendan Zagaeski (Xamarin Team, assistant) 2016-01-13 05:06:24 UTC
*** Bug 37251 has been marked as a duplicate of this bug. ***
Comment 6 Brendan Zagaeski (Xamarin Team, assistant) 2016-01-13 18:00:42 UTC
## Fix

For any users seeing this problem, please run the following command in a Terminal.app command prompt on the Mac build host using the user account that you use to connect from the Mac build host:

chmod og-w "$HOME"




## Brief explanation

If the home directory on the Mac has write permissions enabled for the "other" or "group" categories, then `sshd` shows the following error in `/var/log/system.log`:

> sshd[1715]: Authentication refused: bad ownership or modes for directory /Users/macuser


This in turn means that `sshd` will refuse to use the `authorized_keys` file in "$HOME/.ssh/authorized_keys" for security reasons. This file is required by `sshd` for key-based authentication, but _not_ for password-based authentication. This explains why Xamarin can log in using the password during the initial connection, but then later fails when it tries to use the stored keys to log in again.




## Follow-up

The XamarinVS team can likely add some improvements to the user feedback to help users diagnose and solve this problem more easily.

I will also continue to follow-up with users who have been blocked by the "Could not authenticate the user using the existing ssh keys" message to ensure that repairing the home directory permissions solves the problems in all cases.
Comment 7 Brendan Zagaeski (Xamarin Team, assistant) 2016-01-13 18:06:49 UTC
## Example correct permissions for user home folder

To make sure the `chmod` command (the fix from Comment 6) has left the permissions in the correct expected state, you can run the following command in a Terminal.app command prompt:

ls -ld "$HOME"


Then compare the first column of the output with the following example to make sure all of the "rwx" flags match:

drwxr-xr-x+  1 macuser  staff  22 Nov 16  2014 /Users/macuser
Comment 8 Gerald 2016-01-13 20:11:17 UTC
Appears to be a good fix on a freshly created project.  Changed and compiled to simulator 3X without problem.

Thanks for keeping on top of this one!

Gerald
Comment 9 Brendan Zagaeski (Xamarin Team, assistant) 2016-01-13 20:30:00 UTC
Thanks for verification!

I will mark this bug as "answered" (by Comment 6) for now, and I will file a separate bug to request an improvement in the diagnostic information that XamarinVS provides for this failure scenario. I will add a link to that bug once I have filed it.
Comment 10 Brendan Zagaeski (Xamarin Team, assistant) 2016-01-14 03:57:03 UTC
Follow-up bug to request a more specific error message now filed here: Bug 37674.