Package: redlibssh2
Super fast SSH2 protocol library.redlibssh2provides Python bindings forlibssh2.
Forked from ssh2-python.InstallationBinary wheel packages are provided for Linux, OSX and Windows, all Python versions. Wheel packages haveno dependencies.pipmay need to be updated to be able to install binary wheel packages -pip install-Upip.pipinstallredlibssh2For from source installation instructions, including building against system provided libssh2,see documentation.For creating native system packages for Centos/RedHat, Ubuntu, Debian and Fedora, seeinstructions in the documentation.Who Should Use ThisDevelopers of bespoke SSH clients.Who Should Not Use ThisDevelopers 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 useRedSSH.This library provides bindings to libssh2 and its API closely matches libssh2.If the examples seem long, this is not the right library. UseRedSSH.API Feature SetAt this time all of thelibssh2API 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 theexamples directory.In addition, asredlibssh2is a thin wrapper oflibssh2with Python semantics,its code examplescan be ported straight over to Python with only minimal changes.Library FeaturesThe library usesCythonbased native code extensions as wrappers tolibssh2.Extension features:Thread safe - GIL is released as much as possible. Note that libssh2 does not support sharing sessions across threadsVery low overheadSuper fast as a consequence of the excellent C library it uses and prodigious use of native codeObject oriented - memory freed automatically and safely as objects are garbage collected by PythonUse Python semantics where applicable, such as context manager and iterator support for opening and reading from SFTP file handlesRaise errors as Python exceptionsProvide access tolibssh2error code definitionsQuick StartBoth byte and unicode strings are accepted as arguments and encoded appropriately. To change default encoding,utf-8, change the value ofssh2.utils.ENCODING. Output is always in byte strings.SeeComplete Examplefor an example including socket connect.Please use either the issue tracker for reporting issues with code.Contributions are most welcome!Authentication MethodsConnect and get available authentication methods.from__future__importprint_functionfromssh2.sessionimportSessionsock=<createandconnectsocket>session=Session()session.handshake(sock)print(session.userauth_list())Output will vary depending on SSH server configuration. For example:['publickey','password','keyboard-interactive']Agent Authenticationsession.agent_auth(user)Command Executionchannel=session.open_session()channel.execute('echo Hello')Reading Outputsize,data=channel.read()while(size>0):print(data)size,data=channel.read()HelloExit Codeprint("Exit status:%s"%(channel.get_exit_status()))Exitstatus:0Public Key Authenticationsession.userauth_publickey_fromfile(username,'private_key_file')Passphrase can be provided with thepassphrasekeyword param - seeAPI documentation.Password Authenticationsession.userauth_password(username,'<my password>')SFTP Readfromssh2.sftpimportLIBSSH2_FXF_READ,LIBSSH2_SFTP_S_IRUSRsftp=session.sftp_init()withsftp.open(<remotefiletoread>,LIBSSH2_FXF_READ,LIBSSH2_SFTP_S_IRUSR)asremote_fh,\open(<localfiletowrite>,'wb')aslocal_fh:forsize,datainremote_fh:local_fh.write(data)Complete ExampleA simple usage example looks very similar tolibssh2usage examples.Seeexamples directoryfor more complete example scripts.As mentioned,redlibssh2is intentionally a thin wrapper overlibssh2and directly maps most of its API.Clients using this library can be much simpler to use than interfacing with thelibssh2API directly.from__future__importprint_functionimportosimportsocketfromssh2.sessionimportSessionhost='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()whilesize>0:print(data)size,data=channel.read()channel.close()print("Exit status:%s"%channel.get_exit_status())Output:meExit status: 2SSH Functionality currently implementedSSH channel operations (exec,shell,subsystem) and methodsSSH agent functionalityPublic key authentication and managementSFTP operationsSFTP file handles and attributesSSH port forwarding and tunnellingNon-blocking modeSCP send and receiveListener for port forwardingSubsystem supportHost key checking and manipulationAnd more, as perlibssh2functionality.Comparison with other Python SSH librariesPerformance of above example, compared with Paramiko.timepythonexamples/example_echo.pytimepythonexamples/paramiko_comparison.pyOutput:redlibssh2:real       0m0.141s
user       0m0.037s
sys        0m0.008sparamiko:real       0m0.592s
user       0m0.351s
sys        0m0.021sWhy did you drop manylinux1 wheels?Because frankly the manylinux1 docker containers won’t run on my build hosts because I run up to date software and kernels.
The manylinux1 docker images are also full of extremely old package versions that will not receive updates or security fixes. The way that ParallelSSH handled this was to bundle their own versions of libssh2, OpenSSL and zlib in the repository.