title: Python paramiko SSH to AWS EC2 key authentication fails
body: <p>I’m getting the following error when trying to use paramiko to ssh to an instance in EC2. The pem file is not corrupted. I did use the key to SSH directly from my laptop with no issues. I also tried including the parameter passphrase = None, but still got the same error. I’m pretty new to Python and I’ve never used paramiko before so I’m not sure what else I can do to troubleshoot. Can anyone offer any suggestions? Thanks much for any help. </p>
  
  <pre><code>import boto3
  import paramiko
  
  cert = paramiko.RSAKey.from_private_key_file("C:\\data\\aws-key.pem")
  c = paramiko.SSHClient()
  
  c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  print "connecting..."
  c.connect( hostname = "10.28.73.174", username = "ec2-user", pkey = cert,)
  print "connected!!!"
  stdin, stdout, stderr = ssh.exec_command('ls')
  print stdout.readlines()
  c.close()
  
  connecting...
  Traceback (most recent call last):
  File "k_ssh_to_ec2_instance.py", line 35, in &lt;module&gt;
  c.connect( hostname = "10.28.73.174", username = "ec2-user", pkey = cert,)
  File "C:\Python27\lib\site-packages\paramiko\client.py", line 424, in 
  connect passphrase,
  File "C:\Python27\lib\site-packages\paramiko\client.py", line 714, in _auth 
  raise saved_exception
  paramiko.ssh_exception.AuthenticationException: Authentication failed.
  
  from log
  DEB [20180215-09:46:11.342] thr=1   paramiko.transport: starting thread 
  (client mode): 0x37e9e50L
  DEB [20180215-09:46:11.345] thr=1   paramiko.transport: Local 
  version/idstring: SSH-2.0-paramiko_2.4.0
  DEB [20180215-09:46:11.480] thr=1   paramiko.transport: Remote 
  version/idstring: SSH-2.0-OpenSSH_6.6.1
  INF [20180215-09:46:11.480] thr=1   paramiko.transport: Connected (version 
  2.0, client OpenSSH_6.6.1)
  DEB [20180215-09:46:11.622] thr=1   paramiko.transport: kex algos:
  [u'curve25519-sha256@libssh.org', u'ecdh-...
  DEB [20180215-09:46:11.628] thr=1   paramiko.transport: Kex agreed: ecdh-
  sha2-nistp256
  DEB [20180215-09:46:11.628] thr=1   paramiko.transport: HostKey agreed: ssh-
  ed25519
  DEB [20180215-09:46:11.628] thr=1   paramiko.transport: Cipher agreed: 
  aes128-ctr
  DEB [20180215-09:46:11.628] thr=1   paramiko.transport: MAC agreed: hmac-
  sha2-256
  DEB [20180215-09:46:11.630] thr=1   paramiko.transport: Compression agreed: 
  none
  DEB [20180215-09:46:11.780] thr=1   paramiko.transport: kex engine 
  KexNistp256 specified hash_algo &lt;built-in function openssl_sha256&gt;
  DEB [20180215-09:46:11.782] thr=1   paramiko.transport: Switch to new keys 
  ...
  DEB [20180215-09:46:11.809] thr=2   paramiko.transport: Adding ssh-ed25519 
  host key for 10.28.73.174: 49a9f7afbe7ccfa4f437524af27515e2
  DEB [20180215-09:46:11.809] thr=2   paramiko.transport: Trying SSH key 
  59e06bbe38bb69d943d0d301fcbf3e39
  DEB [20180215-09:46:11.997] thr=1   paramiko.transport: userauth is OK
  INF [20180215-09:46:12.158] thr=1   paramiko.transport: Authentication 
  (publickey) failed.
  DEB [20180215-09:46:12.259] thr=1   paramiko.transport: EOF in transport 
  thread
  </code></pre>