Python paramiko SSH到AWS EC2密钥身份验证失败

时间:2018-02-14 22:27:15

标签: python amazon-ec2 ssh paramiko

我在尝试使用paramiko ssh到EC2中的实例时遇到以下错误。 pem文件未损坏。我确实直接从我的笔记本电脑上使用密钥SSH,没有任何问题。我也试过包含参数passphrase = None,但仍然有同样的错误。我对Python很陌生,之前我从未使用过paramiko,所以我不确定我还能做些什么来排除故障。有人可以提供任何建议吗?非常感谢您的帮助。

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 <module>
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 <built-in function openssl_sha256>
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

0 个答案:

没有答案