# winrm connection to windows server 2012r2 in EC2 - Unauthorized/basic auth failed

**URL:** <https://forum.ansible.com/t/winrm-connection-to-windows-server-2012r2-in-ec2-unauthorized-basic-auth-failed/16311>\
**Category:** Ansible Project\
**Tags:** windows\
**Created:** [September 23, 2014, 8:11pm UTC](https://forum.ansible.com/t/winrm-connection-to-windows-server-2012r2-in-ec2-unauthorized-basic-auth-failed/16311 "2014-09-23T20:11:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_Wozniak](https://avatars.discourse-cdn.com/v4/letter/m/f1d935/32.png) [@Michael\_Wozniak](https://forum.ansible.com/u/Michael_Wozniak)\
**Post date:** [September 23, 2014, 8:11pm UTC](https://forum.ansible.com/t/winrm-connection-to-windows-server-2012r2-in-ec2-unauthorized-basic-auth-failed/16311/1 "2014-09-23T20:11:01Z")

</div>

I’m attempting to set up a windows 2012 system in EC2 which can be accessed/managed with ansible. I’ve used a script like the example ([https://github.com/ansible/ansible/blob/devel/examples/scripts/ConfigureRemotingForAnsible.ps1](https://github.com/ansible/ansible/blob/devel/examples/scripts/ConfigureRemotingForAnsible.ps1)) passed as user\_data at start-up to successfully connect to a windows 2008r2 based system, however I’ve had issues related to memory limits in 2008r2. When I try to use the same script to connect to a 2012r2 based system, I get these errors:

ESTABLISH WINRM CONNECTION FOR USER: Admin1 on PORT 5986 TO IP  
 WINRM CONNECT: transport=plaintext endpoint=[https://IP:5986/wsman](https://IP:5986/wsman)  
 WINRM CONNECTION ERROR: 401 Unauthorized. basic auth failed  
 WINRM CONNECT: transport=plaintext endpoint=[http://IP:5986/wsman](http://IP:5986/wsman)

I can successfully connect to the server with RDP, and as far as I can tell, the winrm settings look correct. Has anyone else experienced similar issues? Any ideas on what could be going wrong?

---

<div class="post-metadata">

**Author:** ![j.r.hawkesworth](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@j.r.hawkesworth](https://forum.ansible.com/u/j.r.hawkesworth)\
**Post date:** [September 23, 2014, 9:25pm UTC](https://forum.ansible.com/t/winrm-connection-to-windows-server-2012r2-in-ec2-unauthorized-basic-auth-failed/16311/2 "2014-09-23T21:25:42Z")

</div>

Worth checking the firewall rules. I think I had something like this happen first time I set up 2012 server, but I probably wasn’t using basic auth.  
From memory I had an error when the following line of the setup script ran:

|
| |
| 

#FIrewall

 |
| | 

netsh advfirewall firewall add rule Profile=public name=“Allow WinRM HTTPS” dir=in localport=5986 protocol=TCP action=allow

 |
| |

I think the problem was the Profile=public part. Yeah, that was it, I had to tweak it to Profile=domain on 2012 but it had been happy on 2008r2 as is. Bear in mind I was using a domain account, so not the same issue as you, but perhaps worth checking the firewall configuration anyway?

Jon

---

<div class="post-metadata">

**Author:** ![Michael\_Wozniak](https://avatars.discourse-cdn.com/v4/letter/m/f1d935/32.png) [@Michael\_Wozniak](https://forum.ansible.com/u/Michael_Wozniak)\
**Post date:** [September 24, 2014, 1:03pm UTC](https://forum.ansible.com/t/winrm-connection-to-windows-server-2012r2-in-ec2-unauthorized-basic-auth-failed/16311/3 "2014-09-24T13:03:48Z")

</div>

I actually have that line switched out for debugging purposes and I just turn off the firewall completely.

This is what I have for now:  
Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled False

I log in to the server with RDP after it’s up and running and I can verify that the firewall shows as disabled in the GUI.

---

<div class="post-metadata">

**Author:** ![Michael\_Wozniak](https://avatars.discourse-cdn.com/v4/letter/m/f1d935/32.png) [@Michael\_Wozniak](https://forum.ansible.com/u/Michael_Wozniak)\
**Post date:** [September 24, 2014, 2:50pm UTC](https://forum.ansible.com/t/winrm-connection-to-windows-server-2012r2-in-ec2-unauthorized-basic-auth-failed/16311/4 "2014-09-24T14:50:43Z")

</div>

Apparently the issue was that I was turning off the firewall before I was setting the new password. The connection works when the password is properly set before turning off the firewall.

---

<div class="post-metadata">

**Author:** ![Mayur\_Barge](https://avatars.discourse-cdn.com/v4/letter/m/a183cd/32.png) [@Mayur\_Barge](https://forum.ansible.com/u/Mayur_Barge)\
**Post date:** [January 15, 2016, 6:33pm UTC](https://forum.ansible.com/t/winrm-connection-to-windows-server-2012r2-in-ec2-unauthorized-basic-auth-failed/16311/5 "2016-01-15T18:33:10Z")

</div>

How did you solved this issue ?  
I’m facing similar issue
