Python 2.7 无法使用Parmiko Python模块SSH到VM
我想ssh到一个VM并执行一些命令。我尝试SSH的VM具有私钥身份验证和要登录的密码短语。此处使用了Paramiko python模块,但由于错误原因保存了\u异常: paramiko.BadAuthenticationType:错误的身份验证类型(允许的类型=['publickey','gssapi keyex','gssapi with mic']) 我在这里尝试使用用户名和密码作为密码短语,并将私钥文件作为密钥文件(也尝试了publick密钥),但无法建立连接 尝试的代码如下所示:Python 2.7 无法使用Parmiko Python模块SSH到VM,python-2.7,ssh,paramiko,ssh-keys,Python 2.7,Ssh,Paramiko,Ssh Keys,我想ssh到一个VM并执行一些命令。我尝试SSH的VM具有私钥身份验证和要登录的密码短语。此处使用了Paramiko python模块,但由于错误原因保存了\u异常: paramiko.BadAuthenticationType:错误的身份验证类型(允许的类型=['publickey','gssapi keyex','gssapi with mic']) 我在这里尝试使用用户名和密码作为密码短语,并将私钥文件作为密钥文件(也尝试了publick密钥),但无法建立连接 尝试的代码如下所示: fro
from paramiko import client
class ssh:
client = None
def __init__ (self, server_addr,username, password, keyfile):
print ("Establishing VM connection")
#Create ssh client.
self.client = client.SSHClient ()
## The following line is required if you want the script to be able to access a server that's not yet in the known_hosts.
self.client.set_missing_host_key_policy (client.AutoAddPolicy())
#Make the connection.
self.client.connect (server_addr, username=username, password=password, key_filename=keyfile);
def sendCommand (self, command):
#Check if connection is made successfully.
if (self.client) :
stdin,stdout,stderr = self.client.exec_command (command)
while not stdout.channel.exit_status_ready ():
alldata = stdout.channel.recv (1024)
while stdout.channel.recv_ready ():
alldata += stdout.channel.recv(1024)
print (str(alldata))
else:
print "Connection is not opened"
密码不是密码短语。首先,从密钥中删除密码短语,并尝试仅使用密钥登录(无密码或密码短语)。这样行吗实际上,您甚至可以使用独立的SSH客户端登录吗?喜欢油灰吗?向我们展示它的事件日志!当从shell尝试时,我能够使用ssh连接到此计算机。但仍然打赌python脚本的身份验证失败。正在获取以下警告,如尝试过的VM的未知ssh rsa主机密钥,
/usr/lib/python2.7/dist packages/paramiko/client.py:95:UserWarning:unknown ssh rsa主机密钥
请显示ssh-v…
output+您是否尝试了没有密码的密钥?