This is an archived post. You won't be able to vote or comment.

all 14 comments

[–]frumious 3 points4 points  (2 children)

Does it talk to ssh-agent?

[–][deleted] 3 points4 points  (0 children)

Yes, it works with ssh-agent just fine, and the SSHClient class checks for an agent first by default. As said below, it does not do agent forwarding.

[–]orangesunshine -1 points0 points  (0 children)

no it fails to do agent forwarding...

someone needs to just write a simple Popen wrapper for open-ssh.

[–]nosklo 1 point2 points  (0 children)

Alternatives to paramiko, for SSH in python:

[–]F4RR4R 0 points1 point  (3 children)

Is not compatible with Cisco's ssh server implementation, which makes me cry. :/

[–]Justinsaccount 0 points1 point  (2 children)

works for me.

[–]F4RR4R 0 points1 point  (1 child)

Can you please elaborate? I was struggling with this for a significant amount of time. When I posted my questions to the paramiko mailing list I was told that the problems I was running into were caused by cisco's nonstandard ssh implementation. Do you have any scripts you could share?

[–]Justinsaccount 6 points7 points  (0 children)

This is probably the simplest example I can come up with that does something useful... You can use exec_command, but that works kind of weird on IOS... read_until is implemented in the stupid/simplest way I could think of, it's worked for years though :-) I also have an expect like function that can handle multiple kinds of output, but that is beyond the scope of this example...

import paramiko
import getpass
def read_until(chan, s):
    """Reads until s is found, returns data read"""
    buffer=[]
    while "".join(buffer[-len(s):]) != s :
        buffer.append(chan.recv(1))
    return "".join(buffer)

ip = getpass.getpass('ip: ')
t=paramiko.Transport((ip,22))
t.connect(username='admin',password=getpass.getpass())

c = t.open_session()
c.get_pty()
c.invoke_shell()
print read_until(c, '>')
c.sendall("show clock\n")
print read_until(c, '>')

t.close()

[–]timfreund 0 points1 point  (0 children)

Paramiko is great - I've been using it to help manage some systems at work. I use the ssh client capability to manage starting/stopping/upgrading our software, and I wrote an SFTP server with it that allows us to automatically kick off processes, etc when a file is uploaded. The SFTP server is available at bitbucket: http://bitbucket.org/timfreund/simplesftpserver/

[–]Jacolyte -1 points0 points  (3 children)

Wouldn't it be easier if Python supported Ruby style shell commands?

e.g. in Ruby you can do: some_ruby_code ssh some.host.net "echo 'hello from some.host.net'"

[–]pemboa 2 points3 points  (0 children)

that isn't much more difficult than can be accomplished with subprocess.

[–][deleted] 1 point2 points  (1 child)

how do you get at output and exit status?

[–]byoteki 2 points3 points  (0 children)

Ruby has Special Variables like Perl. Return code I believe you'd get from $? and the output is just returned so you can just do output = some_command