2

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.

Spur code:

import spur

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

Paramiko code:

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.

Thanks in advance :)

1 Answer 1

3

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)

Sign up to request clarification or add additional context in comments.

5 Comments

See updated answer, does your code look similar? And if yes, is it the same error as before?
Ok yeah it works, now I just get a NoSuchCommand error Command not found l.. :)
Perfect. Don't forget to accept if my answer helped.
For the casual reader, spur.ssh.MissingHostKey.accept is not good practice. There is a reason why Spur (and the SSH tool/protocol) rejects unknown keys by default, and that is to prevent MITM attacks. The "correct" procedure is to check the public key fingerprint against the physical server, or some cloud equivalent, and then add it to your known_hosts file before attempting to connect to it.
Realistically, a better practice here would (after seeing a denied key), should be to prompt (as you would at a normal SSH connection). The "correct" procedure is to phone the admin of the server and have him read the code to you so it can't get hijacked, but that isn't likely to happen.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.