Python library for executing commands interactively over SSH including sudo su - priveleges
Project description
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pysshhelper-0.1.1.tar.gz
.
File metadata
- Download URL: pysshhelper-0.1.1.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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 08dd64abbaf7e64f542081766f82a2ba856e81295d549fbe1d1e72bd33ef6cd5 |
|
MD5 | 7b08b954c804e464de1b36aa1cbe8e68 |
|
BLAKE2b-256 | 549df74ecac00540fda3c6fd39fb51806212e86f3a6a622b2124e95a4d6878fa |
File details
Details for the file pysshhelper-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: pysshhelper-0.1.1-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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 923145c2e2c0b34d84c93feea626e307caf26238a2463f599395420f0a554879 |
|
MD5 | f4ecf9343588404af468da21a8dd232e |
|
BLAKE2b-256 | c64e14ad2e8e355cb8d37e9b23e1ac05490df9ee343d0b4049697bdf0c79e60a |