title: Terraform Azure_Linux_VM makes SSH key not work
body: <p>How do I ssh into my newly created Azure_VM via SSH?</p>
  <p>I am setting up a simple VM via Terraform, assigning it a public IP and an SSH key which I have locally.
  Using the tutorial from the terraform page itself: <a href="https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/linux_virtual_machine" rel="nofollow noreferrer">https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/linux_virtual_machine</a></p>
  <pre><code>resource &quot;azurerm_linux_virtual_machine&quot; &quot;example&quot; {
  ...
    admin_username = &quot;adminuser&quot;
  
    admin_ssh_key {
      username   = &quot;adminuser&quot;
      public_key = file(&quot;~/.ssh/id_rsa.pub&quot;)
    }
  
  [...]
  }
  </code></pre>
  <p>However, after Terraform has created the machine, I can not log into the machine.</p>
  <p><code>$ ssh adminuser@xxx.xxx.xxx.xxx</code>
  yields:</p>
  <pre><code>adminuser@137.117.168.115: Permission denied (publickey).
  </code></pre>
  <hr />
  <p><strong>Tried</strong>:
  First I thought it was the wrong public key. So I checked the public_key on the machine with:</p>
  <pre><code>az vm list --query &quot;[].{SSH: 
  osProfile.linuxConfiguration.ssh.publicKeys[].keyData}&quot; -o json
  </code></pre>
  <p>and compared it to my public key on my local machine.
  They are the same, except for ONE &quot;\n&quot; that is printed in the Azure-VM output.
  Adding a new line to my local public key however did not fix the issue.</p>
  <p><strong>The Catch</strong>:
  Sometimes, after destroying the machine and rebulding it I can login. After and additional <code>terraform destroy</code> and <code>terraform apply</code> it doesn't work anymore. I don
  t get what I am doing wrong</p>
  <p>So, how do I get to SSH into my newly created VM?</p>