简体   繁体   English

无法通过python连接到ssh

[英]Cannot connect to ssh via python

so I just setted up a fresh new raspberry pi and I want it to communicate with python using ssh from my computer to my ssh server, the pi.. I first try to connect using putty and it work, I could execute all the commands I wanted, then I tried using librarys such as Paramiko, Spur and they didn't work. 因此,我刚刚设置了一个新的树莓派pi,并且希望它使用ssh从我的计算机到ssh服务器pi进行python通讯。我首先尝试使用腻子进行连接,并且它可以正常工作,我可以执行所有命令想要,然后我尝试使用Paramiko,Spur等库,但它们没有用。

Spur code: 支线代码:

import spur

shell = spur.SshShell("192.168.1.114", "pi", "raspberry")
result = shell.run("ls")
print result

Paramiko code: Paramiko代码:

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())             
ssh.connect(host, username, password)

Here's the error code: 这是错误代码:

spur.ssh.ConnectionError: Error creating SSH connection
Original error: Server '192.168.1.114' not found in known_hosts

This is the error with spur but it pretty much said the same thing with paramiko. 这是马刺的错误,但与paramiko几乎说了同样的话。

Thanks in advance :) 提前致谢 :)

You need to accept the host key, similarly to what is shown here 您需要接受主机密钥,类似于此处显示的内容

import spur
shell = spur.SshShell("192.168.1.114", 
                      "pi", 
                      "raspberry", 
                      missing_host_key=spur.ssh.MissingHostKey.accept)
result = shell.run("ls")
print result

EDIT: More useful link ( spur documentation ) 编辑:更有用的链接( spur documentation

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM