Skip to main content

Python library for executing commands interactively over SSH including sudo su - priveleges

Project description

GitHub release (latest SemVer) Code style: black Pypi_Version

Please note that the project is in beta phase. Please report any issues you encounter or suggestions you have. We will do our best to address them quickly. Contributions are very welcome!

PySSHHelper

PySSHHelper is a Python library for simplifying SSH connections and interactions with remote servers.

Installation

You can install PySSHHelper using pip:

pip install PySSHHelper

If you would like the most up-to-date version, you can instead install directly from GitHub:

git clone <copied link from github>
cd PySSHHelper
pip install .

Example of usage

from PySSHHelper import SSHConnection

After importing the package, you can use SSHConnection in your code:

# Create an SSH connection object
ssh = SSHConnection(
    host='your_host',
    port=22,
    username_ssh='your_ssh_username',
    password_ssh='your_ssh_password',
    username_sudo='your_sudo_username',
    password_sudo='your_sudo_password',
    verbose=True  # Set verbose to True for debugging information
)

# Connect to the SSH server
ssh.connect()

# Execute a command
output = ssh.execute_command("ls -l")
print(output)

The output variable will contain all output in the console, including escape codes from the terminal, you can use the method to clear them:

print(ssh.cleanup_escape_codes(output))

If you want to execute commands in sudo context:

ssh.elevate_privileges()
print(ssh.execute_command("echo 123 && sleep 5 && echo 321", timeout=10))
print(ssh.execute_command("id"))

And after you can revoke privileges and then continue to execute in normal context

ssh.revoke_privileges()
print(ssh.execute_command("id"))

Also, you can do some SFTP operations

print(ssh.list_directory())
ssh.sftp_get('/remote/path/file.txt', 'local_file.txt')
ssh.sftp_put('local_file.txt', '/remote/path/file.txt')

Close the SSH connection

ssh.close()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pysshhelper-0.1.2.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

pysshhelper-0.1.2-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file pysshhelper-0.1.2.tar.gz.

File metadata

  • Download URL: pysshhelper-0.1.2.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for pysshhelper-0.1.2.tar.gz
Algorithm Hash digest
SHA256 a3029183d510dd127acb4019b04b68f899f925b51f552a2b4e6f01fbf53d0654
MD5 2ea2e7cf745b70106557ba68d0ec5ff7
BLAKE2b-256 c3bf70f2005c556243442a489d5b5423eebde8ba58dc8c7ac82f4cf56d4c904e

See more details on using hashes here.

File details

Details for the file pysshhelper-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: pysshhelper-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 5.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for pysshhelper-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6e1b7f67dca6fc8ae4f154429a4378a9bb071b7e03ecb7385e08ca581f6fdecd
MD5 d689aed1dff4daaba0454df2c88362cd
BLAKE2b-256 c84597f541e84c119f776d893d7caf88aea50fce0d312c59f782110bc04adf5e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page