De Wiki inetshell
Saltar a: navegación, buscar

https://github.com/paramiko/paramiko

https://stackoverflow.com/questions/28723344/how-to-access-a-remote-host-with-paramiko

https://gist.github.com/mlafeldt/841944

import paramiko

def sshConnect(hostname, key_path, cmd = 'ls -al', username = 'root'):
    k = paramiko.ECDSAKey.from_private_key_file(key_path)
    c = paramiko.SSHClient()
    c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    c.connect( hostname = hostname, username = username, pkey = k )
    stdout = c.exec_command(cmd)[1]
    output = str(stdout.read(),'utf-8').replace('\n', '')
    c.close()
    return output
    pass