All Projects → ParallelSSH → Ssh2 Python

ParallelSSH / Ssh2 Python

Licence: lgpl-2.1
Bindings for libssh2 C library.

Programming Languages

python
139335 projects - #7 most used programming language
c
50402 projects - #5 most used programming language
cython
566 projects

Projects that are alternatives of or similar to Ssh2 Python

ssh-python
Python bindings for libssh C library.
Stars: ✭ 19 (-88.55%)
Mutual labels:  ssh, extension, ssh-client
Parallel Ssh
Asynchronous parallel SSH client library.
Stars: ✭ 864 (+420.48%)
Mutual labels:  library, ssh, ssh-client
Ssh Action
GitHub Actions for executing remote ssh commands.
Stars: ✭ 1,095 (+559.64%)
Mutual labels:  ssh, ssh-client
Webssh2
Web SSH Client using ssh2, socket.io, xterm.js, and express. webssh webssh2
Stars: ✭ 1,293 (+678.92%)
Mutual labels:  ssh, ssh-client
Sidedoor
SSH connection daemon for Debian/Raspbian/Ubuntu/etc
Stars: ✭ 97 (-41.57%)
Mutual labels:  ssh, ssh-client
Kitty
💻 KiTTY, a free telnet/ssh client for Windows
Stars: ✭ 791 (+376.51%)
Mutual labels:  ssh, ssh-client
Ssb
Secure Shell Bruteforcer — A faster & simpler way to bruteforce SSH server
Stars: ✭ 832 (+401.2%)
Mutual labels:  ssh, ssh-client
Iap Desktop
IAP Desktop is a Windows application that provides zero-trust Remote Desktop and SSH access to Linux and Windows VMs on Google Cloud.
Stars: ✭ 96 (-42.17%)
Mutual labels:  ssh, ssh-client
Bastillion Ec2
A web-based SSH console to execute commands and manage multiple EC2 instances simultaneously running on Amazon Web Services (AWS).
Stars: ✭ 410 (+146.99%)
Mutual labels:  ssh, ssh-client
Superputty
The SuperPuTTY Window Manager for putty sessions
Stars: ✭ 1,572 (+846.99%)
Mutual labels:  ssh, ssh-client
Ssh
Native SSH client in R based on libssh
Stars: ✭ 111 (-33.13%)
Mutual labels:  ssh, ssh-client
Connectbot
ConnectBot is the first SSH client for Android.
Stars: ✭ 1,763 (+962.05%)
Mutual labels:  ssh, ssh-client
Libssh2
the SSH library
Stars: ✭ 743 (+347.59%)
Mutual labels:  library, ssh
Goph
🤘 The native golang ssh client to execute your commands over ssh connection. 🚀🚀
Stars: ✭ 734 (+342.17%)
Mutual labels:  ssh, ssh-client
Sshw
🐝 ssh client wrapper for automatic login
Stars: ✭ 636 (+283.13%)
Mutual labels:  ssh, ssh-client
Daggy
Daggy - Data Aggregation Utility. Open source, free, cross-platform, server-less, useful utility for remote or local data aggregation and streaming
Stars: ✭ 91 (-45.18%)
Mutual labels:  ssh, ssh-client
Sshfs Gui
SSHFS GUI Wrapper for Mac OS X
Stars: ✭ 154 (-7.23%)
Mutual labels:  ssh, ssh-client
Sshoogr
A Groovy-based DSL for working with remote SSH servers.
Stars: ✭ 327 (+96.99%)
Mutual labels:  ssh, ssh-client
Ssh Mitm
ssh mitm server for security audits supporting public key authentication, session hijacking and file manipulation
Stars: ✭ 335 (+101.81%)
Mutual labels:  ssh, ssh-client
Lssh
List selection type alternative ssh/scp/sftp client. Pure Go.
Stars: ✭ 110 (-33.73%)
Mutual labels:  ssh, ssh-client

ssh2-python

Super fast SSH2 protocol library. ssh2-python provides Python bindings for libssh2_.

.. image:: https://img.shields.io/badge/License-LGPL%20v2.1-blue.svg :target: https://pypi.python.org/pypi/ssh2-python :alt: License .. image:: https://img.shields.io/pypi/v/ssh2-python.svg :target: https://pypi.python.org/pypi/ssh2-python :alt: Latest Version .. image:: https://circleci.com/gh/ParallelSSH/ssh2-python/tree/master.svg?style=svg :target: https://circleci.com/gh/ParallelSSH/ssh2-python .. image:: https://ci.appveyor.com/api/projects/status/github/parallelssh/ssh2-python?svg=true&branch=master :target: https://ci.appveyor.com/project/pkittenis/ssh2-python .. image:: https://img.shields.io/pypi/wheel/ssh2-python.svg :target: https://pypi.python.org/pypi/ssh2-python .. image:: https://img.shields.io/pypi/pyversions/ssh2-python.svg :target: https://pypi.python.org/pypi/ssh2-python .. image:: https://readthedocs.org/projects/ssh2-python/badge/?version=latest :target: http://ssh2-python.readthedocs.org/en/latest/ :alt: Latest documentation

Installation


Binary wheel packages are provided for Linux, OSX and Windows, all Python versions. Wheel packages have no dependencies.

pip may need to be updated to be able to install binary wheel packages - pip install -U pip.

.. code-block:: shell

pip install ssh2-python

For from source installation instructions, including building against system provided libssh2, see documentation <https://ssh2-python.readthedocs.io/en/latest/installation.html#installation-from-source>_.

For creating native system packages for Centos/RedHat, Ubuntu, Debian and Fedora, see instructions in the documentation <http://ssh2-python.readthedocs.io/en/latest/installation.html#system-binary-packages>_.

Who Should Use This


Developers of bespoke SSH clients.

Who Should Not Use This


Developers looking for ready made SSH clients.

This library is not an SSH client.

Developers looking for high level easy to use clients based on this library should use parallel-ssh <https://github.com/ParallelSSH/parallel-ssh>. It provides both single <https://parallel-ssh.readthedocs.io/en/latest/native_single.html> and parallel <https://parallel-ssh.readthedocs.io/en/latest/native_parallel.html>_ clients.

This library provides bindings to libssh2 and its API closely matches libssh2.

If the examples seem long, this is not the right library. Use parallel-ssh <https://github.com/ParallelSSH/parallel-ssh>_.

API Feature Set


At this time all of the libssh2_ API has been implemented up to the libssh2 version in the repository. Please report any missing implementation.

Complete example scripts for various operations can be found in the examples directory_.

In addition, as ssh2-python is a thin wrapper of libssh2 with Python semantics, its code examples <https://libssh2.org/examples/>_ can be ported straight over to Python with only minimal changes.

Library Features

The library uses Cython_ based native code extensions as wrappers to libssh2.

Extension features:

  • Thread safe - GIL is released as much as possible. Note that libssh2 does not support sharing sessions across threads
  • Very low overhead
  • Super fast as a consequence of the excellent C library it uses and prodigious use of native code
  • Object oriented - memory freed automatically and safely as objects are garbage collected by Python
  • Use Python semantics where applicable, such as context manager and iterator support for opening and reading from SFTP file handles
  • Raise errors as Python exceptions
  • Provide access to libssh2 error code definitions

Quick Start


Both byte and unicode strings are accepted as arguments and encoded appropriately. To change default encoding, utf-8, change the value of ssh2.utils.ENCODING. Output is always in byte strings.

See Complete Example_ for an example including socket connect.

Please use either the issue tracker for reporting issues with code or the mail group_ for discussion and questions.

Contributions are most welcome!

Authentication Methods

Connect and get available authentication methods.

.. code-block:: python

from future import print_function

from ssh2.session import Session

sock =

session = Session() session.handshake(sock) print(session.userauth_list())

Output will vary depending on SSH server configuration. For example:

.. code-block:: python

['publickey', 'password', 'keyboard-interactive']

Agent Authentication

.. code-block:: python

session.agent_auth(user)

Command Execution

.. code-block:: python

channel = session.open_session() channel.execute('echo Hello')

Reading Output

.. code-block:: python

size, data = channel.read() while(size > 0): print(data) size, data = channel.read()

.. code-block:: python

Hello

Exit Code

.. code-block:: python

print("Exit status: %s" % (channel.get_exit_status()))

.. code-block:: python

Exit status: 0

Public Key Authentication

.. code-block:: python

session.userauth_publickey_fromfile( username, 'private_key_file')

Passphrase can be provided with the passphrase keyword param - see API documentation <https://ssh2-python.readthedocs.io/en/latest/session.html#ssh2.session.Session.userauth_publickey_fromfile>_.

Password Authentication

.. code-block:: python

session.userauth_password( username, '')

SFTP Read

.. code-block:: python

from ssh2.sftp import LIBSSH2_FXF_READ, LIBSSH2_SFTP_S_IRUSR

sftp = session.sftp_init() with sftp.open(, LIBSSH2_FXF_READ, LIBSSH2_SFTP_S_IRUSR) as remote_fh,
open(, 'wb') as local_fh: for size, data in remote_fh: local_fh.write(data)

Complete Example


A simple usage example looks very similar to libssh2 usage examples <https://www.libssh2.org/examples/>_.

See examples directory <https://github.com/ParallelSSH/ssh2-python/tree/master/examples>_ for more complete example scripts.

As mentioned, ssh2-python is intentionally a thin wrapper over libssh2 and directly maps most of its API.

Clients using this library can be much simpler to use than interfacing with the libssh2 API directly.

.. code-block:: python

from future import print_function

import os import socket

from ssh2.session import Session

host = 'localhost' user = os.getlogin()

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect((host, 22))

session = Session() session.handshake(sock) session.agent_auth(user)

channel = session.open_session() channel.execute('echo me; exit 2') size, data = channel.read() while size > 0: print(data) size, data = channel.read() channel.close() print("Exit status: %s" % channel.get_exit_status())

:Output:

me

Exit status: 2

SSH Functionality currently implemented


  • SSH channel operations (exec,shell,subsystem) and methods
  • SSH agent functionality
  • Public key authentication and management
  • SFTP operations
  • SFTP file handles and attributes
  • SSH port forwarding and tunnelling
  • Non-blocking mode
  • SCP send and receive
  • Listener for port forwarding
  • Subsystem support
  • Host key checking and manipulation

And more, as per libssh2_ functionality.

Comparison with other Python SSH libraries

Performance of above example, compared with Paramiko.

.. code-block:: shell

time python examples/example_echo.py time python examples/paramiko_comparison.py

:Output:

ssh2-python::

 real	0m0.141s
 user	0m0.037s
 sys	0m0.008s

paramiko::

 real	0m0.592s
 user	0m0.351s
 sys	0m0.021s

.. _libssh2: https://www.libssh2.org .. _Cython: https://www.cython.org .. _examples directory: https://github.com/ParallelSSH/ssh2-python/tree/master/examples .. _mail group: https://groups.google.com/forum/#!forum/ssh2-python

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].