Automate SSH in python easily!

Overview

RedExpect

PyPI License: GPL v2

Test Status Documentation Status Coverage Status

RedExpect makes automating remote machines over SSH very easy to do and is very fast in doing exactly what you ask of it. Based on ssh2-python (which provides libssh2 bindings for python) and made into an easy to use SSH library via RedSSH. If you're familiar with using expect but would like the easy of use and accessibilty of python, then look no further!

Installing

RedExpect can be installed via pip with pip install redexpect or the latest commit, which may not be the most stable, from git with pip install git://[email protected]/Red_M/RedExpect.git

Documentation

99% of questions around how to do something should be answered in the documentation. If something is not there please raise an issue so it can be added to the documentation. Now with autodocs!

Why not use [other software]?

I've found other automation libraries or solutions lacking, such as:

  • Compatibility with remote servers (odd servers causes the library to be unable to connect).
  • Feature set is limited (eg, no tunneling).
  • Focuses on only connecting to Linux servers.
  • Requires an agent to be installed, a state file to be present or a master "server".
  • Poor performance.

TO DO

  • Update unit tests to match RedSSH's tests
  • More examples
You might also like...
The leading native Python SSHv2 protocol library.

Paramiko Paramiko: Python SSH module Copyright: Copyright (c) 2009 Robey Pointer [email protected] Copyright: Copyright (c) 2020 Jeff Forcier

Official Python client library for kubernetes

Kubernetes Python Client Python client for the kubernetes API. Installation From source: git clone --recursive https://github.com/kubernetes-client/py

Python job scheduling for humans.

schedule Python job scheduling for humans. Run Python functions (or any other callable) periodically using a friendly syntax. A simple to use API for

A cron monitoring tool written in Python & Django
A cron monitoring tool written in Python & Django

Healthchecks Healthchecks is a cron job monitoring service. It listens for HTTP requests and email messages ("pings") from your cron jobs and schedule

Remote Desktop Protocol in Twisted Python

RDPY Remote Desktop Protocol in twisted python. RDPY is a pure Python implementation of the Microsoft RDP (Remote Desktop Protocol) protocol (client a

Python utility function to communicate with a subprocess using iterables: for when data is too big to fit in memory and has to be streamed

iterable-subprocess Python utility function to communicate with a subprocess using iterables: for when data is too big to fit in memory and has to be

Linux, Jenkins, AWS, SRE, Prometheus, Docker, Python, Ansible, Git, Kubernetes, Terraform, OpenStack, SQL, NoSQL, Azure, GCP, DNS, Elastic, Network, Virtualization. DevOps Interview Questions
Linux, Jenkins, AWS, SRE, Prometheus, Docker, Python, Ansible, Git, Kubernetes, Terraform, OpenStack, SQL, NoSQL, Azure, GCP, DNS, Elastic, Network, Virtualization. DevOps Interview Questions

Linux, Jenkins, AWS, SRE, Prometheus, Docker, Python, Ansible, Git, Kubernetes, Terraform, OpenStack, SQL, NoSQL, Azure, GCP, DNS, Elastic, Network, Virtualization. DevOps Interview Questions

Push Container Image To Docker Registry In Python

push-container-image-to-docker-registry 概要 push-container-image-to-docker-registry は、エッジコンピューティング環境において、特定のエッジ端末上の Private Docker Registry に特定のコンテナイメー

Get Response Of Container Deployment Kube with python

get-response-of-container-deployment-kube 概要 get-response-of-container-deployment-kube は、例えばエッジコンピューティング環境のコンテナデプロイメントシステムにおいて、デプロイ元の端末がデプロイ先のコンテナデプロイ

Comments
  • command output not returned immediately

    command output not returned immediately

    I have a script that looks like:

    import redexpect
    expect = redexpect.RedExpect()
    expect.connect( ... )
    output = expect.command( 'mount', remove_newline = True )
    print( output )
    print( "---" )
    output = expect.command( 'ls -la', remove_newline = True )
    print( output )
    expect.exit()
    

    The output from the 'mount' command is not returned until the output variable is assigned with the 'ls -la' command.

    There is probably something I am misunderstanding about how this should work.

    opened by James-Hudson3010 4
  • Exit function fails when using exit function a second time after reconnecting

    Exit function fails when using exit function a second time after reconnecting

    I have tried using the same object to connect, run a command, and then disconnect, and then reconnect again and repeat the process. This almost works as expected. I can reconnect using the same object, and successfully run a command, but I cannot then use the exit function to close the connection. I receive the following error:

    File "C:\Users\...\venv\lib\site-packages\redssh\redssh.py", line 588, in exit
        if not self._ssh_keepalive_thread==None:
    AttributeError: 'RedExpect' object has no attribute '_ssh_keepalive_thread'
    

    I can still continue to run commands with the same object, but I cannot find a way to simply close the connection entirely, after a I reconnect.

    The closest work around I have found is, after using exit the first time, I delete the object, but this is inconvenient to me to have to recreate the object over again.

    opened by jdhdt 3
  • redssh.exceptions.AuthenticationFailedException

    redssh.exceptions.AuthenticationFailedException

    dear all. I have a target host that I can ssh to it without password. But I fail login using redExpect :

    
    (coba2) debian@debian-mon:~/coba2$ ssh [email protected] -p 3322
    Last login: Fri Sep 18 10:23:25 2020 from 10.90.200.57
    [root@candibinangun ~]# exit
    logout
    Connection to 10.90.200.55 closed.
    (coba2) debian@debian-mon:~/coba2$ python
    Python 3.8.5 (default, Aug 28 2020, 06:44:01) 
    [GCC 8.3.0] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import redexpect
    >>> 
    >>> sshObj = redexpect.RedExpect()
    >>> sshObj.login('10.90.200.55', port=3322, username='root', timeout=1.5)
    WARN: ('Host %s not found in known hosts collection', b'10.90.200.55')
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/home/debian/.local/share/virtualenvs/coba2-gQE_YhKQ/lib/python3.8/site-packages/redexpect/redexpect.py", line 75, in login
        self.connect(*args,**kwargs)
      File "/home/debian/.local/share/virtualenvs/coba2-gQE_YhKQ/lib/python3.8/site-packages/redssh/redssh.py", line 358, in connect
        self._auth(username,password,allow_agent,host_based,key_filepath,passphrase,look_for_keys)
      File "/home/debian/.local/share/virtualenvs/coba2-gQE_YhKQ/lib/python3.8/site-packages/redssh/redssh.py", line 222, in _auth
        raise(exceptions.AuthenticationFailedException(list(set(auth_types_tried))))
    redssh.exceptions.AuthenticationFailedException: Failed to authenticated to remote server via: 
    
    

    Yes I read the docs, but I can't understand which part of it to fix my problem

    Sincerely -bino-

    opened by binooetomo 1
  • Installation Error

    Installation Error

    Hi, I'm trying to install redexpect by I get the following error when running pip install redexpect. I was able to install redexpect in the past but now is giving a problem installing redlibssh2.

    Collecting redlibssh2 Using cached redlibssh2-2.0.2.tar.gz (1.1 MB) Building wheels for collected packages: redlibssh2 Building wheel for redlibssh2 (setup.py) ... error ERROR: Command errored out with exit status 1: command: 'c:\users\xxxxx\appdata\local\continuum\anaconda3\envs\red74\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\xxxxx\AppData\Local\Temp\pip-install-o0ufb3xf\redlibssh2_821735bbfe6d4df5911319c7247df474\setup.py'"'"'; file='"'"'C:\Users\xxxxx\AppData\Local\Temp\pip-install-o0ufb3xf\redlibssh2_821735bbfe6d4df5911319c7247df474\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' bdist_wheel -d 'C:\Users\xxxxx\AppData\Local\Temp\pip-wheel-ou3d1d8c' cwd: C:\Users\xxxxx\AppData\Local\Temp\pip-install-o0ufb3xf\redlibssh2_821735bbfe6d4df5911319c7247df474
    Complete output (11 lines): 'cmake' is not recognized as an internal or external command, operable program or batch file. Traceback (most recent call last): File "", line 1, in File "C:\Users\xxxxx\AppData\Local\Temp\pip-install-o0ufb3xf\redlibssh2_821735bbfe6d4df5911319c7247df474\setup.py", line 36, in build_ssh2() File "C:\Users\xxxxx\AppData\Local\Temp\pip-install-o0ufb3xf\redlibssh2_821735bbfe6d4df5911319c7247df474_setup_libssh2.py", line 24, in build_ssh2 shell=True, env=os.environ) File "c:\users\xxxxx\appdata\local\continuum\anaconda3\envs\red74\lib\subprocess.py", line 347, in check_call raise CalledProcessError(retcode, cmd) subprocess.CalledProcessError: Command 'cmake ../libssh2 -DBUILD_SHARED_LIBS=ON -DENABLE_ZLIB_COMPRESSION=ON -DENABLE_CRYPT_NONE=ON -DENABLE_MAC_NONE=ON -DCRYPTO_BACKEND=OpenSSL' returned non-zero exit status 1.

    ERROR: Failed building wheel for redlibssh2 Running setup.py clean for redlibssh2 Failed to build redlibssh2 Installing collected packages: redlibssh2 Running setup.py install for redlibssh2 ... error ERROR: Command errored out with exit status 1: command: 'c:\users\xxxxx\appdata\local\continuum\anaconda3\envs\red74\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\xxxxx\AppData\Local\Temp\pip-install-o0ufb3xf\redlibssh2_821735bbfe6d4df5911319c7247df474\setup.py'"'"'; file='"'"'C:\Users\xxxxx\AppData\Local\Temp\pip-install-o0ufb3xf\redlibssh2_821735bbfe6d4df5911319c7247df474\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' install --record 'C:\Users\xxxxx\AppData\Local\Temp\pip-record-jhh0p91i\install-record.txt' --single-version-externally-managed --compile --install-headers 'c:\users\xxxxx\appdata\local\continuum\anaconda3\envs\red74\Include\redlibssh2' cwd: C:\Users\xxxxx\AppData\Local\Temp\pip-install-o0ufb3xf\redlibssh2_821735bbfe6d4df5911319c7247df474
    Complete output (11 lines): 'cmake' is not recognized as an internal or external command, operable program or batch file. Traceback (most recent call last): File "", line 1, in File "C:\Users\xxxxx\AppData\Local\Temp\pip-install-o0ufb3xf\redlibssh2_821735bbfe6d4df5911319c7247df474\setup.py", line 36, in build_ssh2() File "C:\Users\xxxxx\AppData\Local\Temp\pip-install-o0ufb3xf\redlibssh2_821735bbfe6d4df5911319c7247df474_setup_libssh2.py", line 24, in build_ssh2 shell=True, env=os.environ) File "c:\users\xxxxx\appdata\local\continuum\anaconda3\envs\red74\lib\subprocess.py", line 347, in check_call raise CalledProcessError(retcode, cmd) subprocess.CalledProcessError: Command 'cmake ../libssh2 -DBUILD_SHARED_LIBS=ON -DENABLE_ZLIB_COMPRESSION=ON -DENABLE_CRYPT_NONE=ON -DENABLE_MAC_NONE=ON -DCRYPTO_BACKEND=OpenSSL' returned non-zero exit status 1. ---------------------------------------- ERROR: Command errored out with exit status 1: 'c:\users\xxxxx\appdata\local\continuum\anaconda3\envs\red74\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\xxxxx\AppData\Local\Temp\pip-install-o0ufb3xf\redlibssh2_821735bbfe6d4df5911319c7247df474\setup.py'"'"'; file='"'"'C:\Users\xxxxx\AppData\Local\Temp\pip-install-o0ufb3xf\redlibssh2_821735bbfe6d4df5911319c7247df474\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' install --record 'C:\Users\xxxxx\AppData\Local\Temp\pip-record-jhh0p91i\install-record.txt' --single-version-externally-managed --compile --install-headers 'c:\users\xxxxx\appdata\local\continuum\anaconda3\envs\red74\Include\redlibssh2' Check the logs for full command output.

    opened by glss95 7
Owner
Red_M
Red_M
SSH tunnels to remote server.

Author: Pahaz Repo: https://github.com/pahaz/sshtunnel/ Inspired by https://github.com/jmagnusson/bgtunnel, which doesn't work on Windows. See also: h

Pavel White 1k Dec 28, 2022
Manage your SSH like a boss.

--- storm is a command line tool to manage your ssh connections. features adding, editing, deleting, listing, searching across your SSHConfig. command

Emre Yılmaz 3.9k Jan 3, 2023
Asynchronous parallel SSH client library.

parallel-ssh Asynchronous parallel SSH client library. Run SSH commands over many - hundreds/hundreds of thousands - number of servers asynchronously

null 1.1k Dec 31, 2022
SSH to WebSockets Bridge

wssh wssh is a SSH to WebSockets Bridge that lets you invoke a remote shell using nothing but HTTP. The client connecting to wssh doesn't need to spea

Andrea Luzzardi 1.3k Dec 25, 2022
Software to automate the management and configuration of any infrastructure or application at scale. Get access to the Salt software package repository here:

Latest Salt Documentation Open an issue (bug report, feature request, etc.) Salt is the world’s fastest, most intelligent and scalable automation engi

SaltStack 12.9k Jan 4, 2023
Manage your azure VM easily!

Azure-manager Manage your VM in Azure using cookies.

Team 1injex 129 Dec 17, 2022
Python IMDB Docker - A docker tutorial to containerize a python script.

Python_IMDB_Docker A docker tutorial to containerize a python script. Build the docker in the current directory: docker build -t python-imdb . Run the

Sarthak Babbar 1 Dec 30, 2021
Honcho: a python clone of Foreman. For managing Procfile-based applications.

___ ___ ___ ___ ___ ___ /\__\ /\ \ /\__\ /\ \ /\__\ /\

Nick Stenning 1.5k Jan 3, 2023
Cross-platform lib for process and system monitoring in Python

Home Install Documentation Download Forum Blog Funding What's new Summary psutil (process and system utilities) is a cross-platform library for retrie

Giampaolo Rodola 9k Jan 2, 2023
A Python library for the Docker Engine API

Docker SDK for Python A Python library for the Docker Engine API. It lets you do anything the docker command does, but from within Python apps – run c

Docker 6.1k Dec 31, 2022