title: Can't connect using SSH while using Ansible, but command prompt works just fine
body: <h2>Problem</h2>
  <p>I'm trying to connect to a few of my <strong>Linux EC2 Instances</strong> and I'm getting this weird behavior depending on how I'm connecting to it.</p>
  <h3>Terminal</h3>
  <p>If I try to connect to it from the terminal using the following command:</p>
  <pre><code>ssh -i &quot;&lt;PATH_TO_PRIVATE_KEY_FILE&gt;&quot; ec2-user@&lt;PRIVATE_IP_ADDRESS&gt;
  </code></pre>
  <p>I'm able to connect successfully.</p>
  <h3>Visual Studio Code Remote Explorer</h3>
  <p>I am able to connect to the instance successfully.</p>
  <h3>Paramiko</h3>
  <pre class="lang-py prettyprint-override"><code># Create a new connection.
  ssh_conn = paramiko.SSHClient()
  ssh_conn.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  
  # Load the Private Key.
  my_rsa_key = paramiko.RSAKey.from_private_key_file(key_file)
  
  # Connect to the server.
  _session = ssh_conn.connect(
      hostname=host,
      port=port,
      username=username,
      pkey=my_rsa_key,
      timeout=5
  )
  </code></pre>
  <p>Here I get a timeout error. Here I'm confident the code is fine because it works with some instances but not others and the issue seem to always be the connection portion.</p>
  <h3>Ansible</h3>
  <p>When I try to connect to the same EC2 instance using Ansible I get <code>Permission denied (publickey)</code>. Now I can confidently say it's not a syntax error inside of the Ansible code because when I run the same code on a few different EC2 instances it runs fine without problem. The issue is only related to the connection process.</p>
  <h2>Thoughts?</h2>
  <p>The behavior is limited to a few instances and it's always the same issue. What would cause behavior like this or how could I go about trying to diagnose the problem? I'm happy to add more detail but I wanted to start here and see what people thought.</p>