Skip to content
/ PySsh2 Public

PySsh2: A ctypes-based python wrapper around libssh2

Notifications You must be signed in to change notification settings

ihrwein/PySsh2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

52 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PySSH2

An SSH library for Python3 to execute commands in a remote shell.

Overview

This library lets you open a remote shell through SSH. It was tested with Linux and Cisco IOS remotes and worked perfectly.

It doesn't support Python2.

Installation

First install libssh2. The name of the library may depend on your OS, you can also try the libssh2 name. PySSH2 will need th libssh2.so file.

# apt-get install libssh2-1

Then you can install PySSH2:

pip3 install git+https://github.com/ihrwein/PySsh2

Usage

The following example works like the ssh command. It reads from your stdin and sends the commands to the remote computer. You can find this example as the clissh.py file.

import pyssh2
import time

HOST_NAME = "localhost"
USER_NAME = "sshuser"
PASSWORD = ""
PORT = 10022

def main():
    ssh = pyssh2.connect(USER_NAME, PASSWORD, HOST_NAME, PORT)
    shell = ssh.shell()
    print(shell.read(), end="")
    while True:
        try:
            command = input()
            shell.write(command)
            print(shell.read(), end="")
        except EOFError as err:
            ssh.close()
            break

if __name__ == "__main__":
    main()

About

PySsh2: A ctypes-based python wrapper around libssh2

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages