title: 401 Unauthorized error with WebDeploy using non-administrator user
body: <p>&lt;TLDR><br>
  Is it at all possible to use ms web deploy to deploy a web application to a <strong>remote host</strong> from <strong>the command line</strong> with a <strong>non-administrator</strong> user?<br>
  &lt;/TLDR></p>
  
  <p>I have followed every point  in Microsoft's guide for <a href="http://www.iis.net/learn/install/installing-publishing-technologies/installing-and-configuring-web-deploy" rel="nofollow noreferrer">Installing and Configuring Web Deploy</a>. My goal is to be able to do a remote web deploy with an IIS user/non-administrator user.</p>
  
  <p>After doing all the steps as described under <em>Install and configure web deploy for non-administrator deployments</em>, I get the following log messages (indicating that everything is OK):</p>
  
  <pre><code>Publish enabled for 'deploy_user'
  Granted 'deploy_user' full control on 'C:\inetpub\wwwroot'
  Successfully created settings file 'C:\Users\...\Desktop\deploy_user_Default Web Site.PublishSettings'
  </code></pre>
  
  <p>Next, when I from my local machine try to run the following command:</p>
  
  <pre><code>.\my_deploy_package.cmd /M:https://machine_name:8172/msdeploy.axd -allowUntrusted /U:deploy_user /P:deploy_password /A:Basic /T
  </code></pre>
  
  <p>I get an error message saying: <em>Error: The remote server returned an error: (401) Unauthorized.</em></p>
  
  <p>If I on the target machine go into the Event Viewer > Custom Views > Administratove Events, I see a "matching" error with this message:</p>
  
  <blockquote>
    <p>IISWMSVC_AUTHORIZATION_SERVER_NOT_ALLOWED</p>
    
    <p>Only Windows Administrators are allowed to connect using a server
    connection. Other users should use the 'Connect To Site or
    Application' task to be able to connect.</p>
    
    <p>Process:WMSvc User=deploy_user</p>
  </blockquote>
  
  <p>This error is the exact same as described in <a href="https://stackoverflow.com/questions/2874939/how-to-use-msdeploy-and-target-a-specific-site">this question</a>. And the <a href="https://stackoverflow.com/a/6036949/310001">accepted answer</a> suggests that what I've already done is the correct approach.</p>
  
  <p>I have tried several workarounds suggested, like <a href="https://stackoverflow.com/questions/4807049/webdeploy-401-unauthorized-error">this</a>, but nothing seems to be helping. Management Service is set to allow remote connections (both Windows and IIS Manager), and I have run the configuration for both a build-in windows user (non-administrator) and an IIS Manager User, and still the same error. As soon as I run the deploy command with an administrator user however, it succeeds.</p>
  
  <p>I <em>am</em> allowed to connect remotely through the IIS gui with my non-administrator deploy_user user (in IIS: <em>Connect to Site > [server url]/[site name] > deploy_user/deploy_password</em>), indicating that the necessary rights and rules are configured. It is however when I try to run the deploy script command line - with the same user - that it fails.</p>
  
  <p>And if it actually <em>is</em> as the error message indicates, that any non-admin user can <em>only</em> use <em>Connect To Site or Application</em> through IIS Manager, what is then the recommended way to do deploys like this from the command line/a build server? I don't really wan't to enter the username/password of an admin user in clear-text in the config at the build server...</p>
  
  <p>One option I've found that's working, is that if your build server and the machine you try to deploy to have a common Active Directory (or other means of sharing users), you can skip the <code>/A:Basic</code> flag and leave out the username and password altogether. You must only make sure that the user running the deploy also have administrator rights on the deploy target. However, in one case for us the build server and deploy target <em>doesn't</em> have a common user base, so this isn't an option and we're back to username/password in clear-text - which isn't desirable at all.</p>