跳转到主要内容

SSH for Humans

项目描述

Hussh: SSH for humans.

image image PyPI - Wheel Actions status

Hussh(发音为“hush”)是一个客户端ssh库,它通过高级接口提供低级性能。

Hussh使用pyo3在Rust的ssh2库周围创建Python绑定。

安装

pip install hussh

快速入门

Hussh目前仅提供一个Connection类作为您的主要接口。

from hussh import Connection

conn = Connection(host="my.test.server", username="user", password="pass")
result = conn.execute("ls")
print(result.stdout)

就是这样!只需一个导入和类实例化即可

  • 执行命令
  • 执行SCP操作
  • 执行SFTP操作
  • 获取交互式shell

为什么选择Hussh?

  • 🔥 极快!
  • 🪶 极其轻量级!
  • 🧠 超级易用!

基准测试

Hussh展示了您期望从低级ssh库中获得的表现。Hussh在总内存和内存分配方面也更为轻量级。

本地服务器 Local Server Benchmarks

远程服务器 Remote Server Benchmarks

亲自试试!

Hussh的基准测试脚本也开源在存储库中的benchmarks目录中。克隆存储库,遵循设置说明,然后让我们知道它的表现如何!

认证

您已经见过基于密码的身份验证,但这里再展示一次。

conn = Connection(host="my.test.server", username="user", password="pass")

#  or leave out username and connect as root
conn = Connection(host="my.test.server", password="pass")

如果您更喜欢基于密钥的身份验证,Hussh 也能做到。

conn = Connection(host="my.test.server", private_key="~/.ssh/id_rsa")

# If your key is password protected, just use the password argument
conn = Connection(host="my.test.server", private_key="~/.ssh/id_rsa", password="pass")

如果已经建立了它,Hussh 还能进行基于代理的身份验证。

conn = Connection("my.test.server")

执行命令

ssh 库最基本的基础是能够执行对远程主机的命令。对于 Hussh,只需使用 Connection 对象的 execute 方法。

result = conn.execute("whoami")
print(result.stdout, result.stderr, result.status)

每次执行都会返回一个包含命令的 stdout、stderr 和状态的 SSHResult 对象。

SFTP

如果您需要将文件传输到/从远程主机,SFTP 可能是您的最佳选择。

写入文件和数据

# write a local file to the remote destination
conn.sftp_write(local_path="/path/to/my/file", remote_path="/dest/path/file")

# Write UTF-8 data to a remote file
conn.sftp_write_data(data="Hello there!", remote_path="/dest/path/file")

读取文件

# You can copy a remote file to a local destination
conn.sftp_read(remote_path="/dest/path/file", local_path="/path/to/my/file")
# Or copy the remote file contents to a string
contents = conn.sftp_read(remote_path="/dest/path/file")

将文件从一个连接复制到另一个连接

Hussh 提供了一个快捷方式,允许您在两个已建立的连接之间复制文件。

source_conn = Connection("my.first.server")
dest_conn = Connection("my.second.server", password="secret")
# Copy from source to destination
source_conn.remote_copy(source_path="/root/myfile.txt", dest_conn=dest_conn)

默认情况下,如果您没有传入备用的 dest_path,Hussh 将将其复制到与源相同的路径。

SCP

对于支持 SCP 的远程服务器,Hussh 也能做到。

写入文件和数据

# write a local file to the remote destination
conn.scp_write(local_path="/path/to/my/file", remote_path="/dest/path/file")

# Write UTF-8 data to a remote file
conn.scp_write_data(data="Hello there!", remote_path="/dest/path/file")

读取文件

# You can copy a remote file to a local destination
conn.scp_read(remote_path="/dest/path/file", local_path="/path/to/my/file")
# Or copy the remote file contents to a string
contents = conn.scp_read(remote_path="/dest/path/file")

跟踪文件

Hussh 提供了一个内置方法,可以通过 Connectiontail 方法跟踪文件。

with conn.tail("/path/to/file.txt") as tf:
   # perform some actions or wait
   print(tf.read())  # at any time, you can read any unread contents
   # when you're done tailing, exit the context manager
print(tf.contents)

交互式 Shell

如果您需要保持一个 Shell 打开以进行更复杂的交互,您可以从 Connection 类实例获取一个 InteractiveShell 实例。要使用交互式 Shell,建议使用 Connection 类的 shell() 上下文管理器。您可以使用 send 方法向 Shell 发送命令,然后在退出上下文管理器时从 result 获取结果。

with conn.shell() as shell:
   shell.send("ls")
   shell.send("pwd")
   shell.send("whoami")

print(shell.result.stdout)

注意: read 方法向 Shell 发送 EOF,因此在调用 read 之后将无法发送更多命令。如果您想发送更多命令,您需要创建一个新的 InteractiveShell 实例。

免责声明

这是一个非常早期的项目,不应在生产代码中使用!甚至没有适当的异常处理,所以 try/except 不会工作。话虽如此,试试看,并告诉我您的想法!

未来功能

  • 适当的异常处理
  • 并发动作类
  • 异步连接类
  • 低级绑定
  • 其他代码库改进
  • 待定...

项目详情


下载文件

下载适合您平台文件的文件。如果您不确定要选择哪个,请了解更多关于 安装包 的信息。

源代码分发

hussh-0.1.7.tar.gz (534.7 kB 查看哈希)

上传时间 源代码

构建分发

hussh-0.1.7-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.9 MB 查看哈希)

上传时间 PyPy manylinux: glibc 2.17+ x86-64

hussh-0.1.7-pp310-pypy310_pp73-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.9 MB 查看哈希值)

上传于 PyPy manylinux: glibc 2.17+ ppc64le

hussh-0.1.7-pp310-pypy310_pp73-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.6 MB 查看哈希值)

上传于 PyPy manylinux: glibc 2.17+ ARMv7l

hussh-0.1.7-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.2 MB 查看哈希值)

上传于 PyPy manylinux: glibc 2.17+ ARM64

hussh-0.1.7-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.9 MB 查看哈希值)

上传于 PyPy manylinux: glibc 2.17+ x86-64

hussh-0.1.7-pp39-pypy39_pp73-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.9 MB 查看哈希值)

上传于 PyPy manylinux: glibc 2.17+ ppc64le

hussh-0.1.7-pp39-pypy39_pp73-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.6 MB 查看哈希值)

上传于 PyPy manylinux: glibc 2.17+ ARMv7l

hussh-0.1.7-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.2 MB 查看哈希值)

上传于 PyPy manylinux: glibc 2.17+ ARM64

hussh-0.1.7-pp38-pypy38_pp73-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.9 MB 查看哈希值)

上传于 PyPy manylinux: glibc 2.17+ ppc64le

hussh-0.1.7-pp38-pypy38_pp73-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.6 MB 查看哈希值)

上传于 PyPy manylinux: glibc 2.17+ ARMv7l

hussh-0.1.7-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.2 MB 查看哈希值)

上传于 PyPy manylinux: glibc 2.17+ ARM64

hussh-0.1.7-cp312-none-win_amd64.whl (293.2 kB 查看哈希值)

上传于 CPython 3.12 Windows x86-64

hussh-0.1.7-cp312-none-win32.whl (270.6 kB 查看哈希值)

上传于 CPython 3.12 Windows x86

hussh-0.1.7-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.9 MB 查看哈希值)

上传于 CPython 3.12 manylinux: glibc 2.17+ x86-64

hussh-0.1.7-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.9 MB 查看哈希值)

上传于 CPython 3.12 manylinux: glibc 2.17+ ppc64le

hussh-0.1.7-cp312-cp312-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.6 MB 查看哈希值)

上传于 CPython 3.12 manylinux: glibc 2.17+ ARMv7l

hussh-0.1.7-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.2 MB 查看哈希值)

上传于 CPython 3.12 manylinux: glibc 2.17+ ARM64

hussh-0.1.7-cp312-cp312-macosx_11_0_arm64.whl (364.1 kB 查看哈希值)

上传于 CPython 3.12 macOS 11.0+ ARM64

hussh-0.1.7-cp312-cp312-macosx_10_12_x86_64.whl (372.1 kB 查看哈希值)

上传于 CPython 3.12 macOS 10.12+ x86-64

hussh-0.1.7-cp311-none-win_amd64.whl (293.7 kB 查看哈希值)

上传于 CPython 3.11 Windows x86-64

hussh-0.1.7-cp311-none-win32.whl (271.1 kB 查看哈希值)

上传于 CPython 3.11 Windows x86

hussh-0.1.7-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.9 MB 查看哈希值)

上传时间: CPython 3.11 manylinux: glibc 2.17+ x86-64

hussh-0.1.7-cp311-cp311-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.9 MB 查看哈希值)

上传时间: CPython 3.11 manylinux: glibc 2.17+ ppc64le

hussh-0.1.7-cp311-cp311-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.6 MB 查看哈希值)

上传时间: CPython 3.11 manylinux: glibc 2.17+ ARMv7l

hussh-0.1.7-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.2 MB 查看哈希值)

上传时间: CPython 3.11 manylinux: glibc 2.17+ ARM64

hussh-0.1.7-cp311-cp311-macosx_11_0_arm64.whl (364.5 kB 查看哈希值)

上传时间: CPython 3.11 macOS 11.0+ ARM64

hussh-0.1.7-cp311-cp311-macosx_10_12_x86_64.whl (372.8 kB 查看哈希值)

上传时间: CPython 3.11 macOS 10.12+ x86-64

hussh-0.1.7-cp310-none-win_amd64.whl (293.9 kB 查看哈希值)

上传时间: CPython 3.10 Windows x86-64

hussh-0.1.7-cp310-none-win32.whl (270.6 kB 查看哈希值)

上传时间: CPython 3.10 Windows x86

hussh-0.1.7-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.9 MB 查看哈希值)

上传时间: CPython 3.10 manylinux: glibc 2.17+ x86-64

hussh-0.1.7-cp310-cp310-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.9 MB 查看哈希值)

上传时间: CPython 3.10 manylinux: glibc 2.17+ ppc64le

hussh-0.1.7-cp310-cp310-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.6 MB 查看哈希值)

上传于 CPython 3.10 manylinux: glibc 2.17+ ARMv7l

hussh-0.1.7-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.2 MB 查看哈希值)

上传于 CPython 3.10 manylinux: glibc 2.17+ ARM64

hussh-0.1.7-cp310-cp310-macosx_11_0_arm64.whl (364.6 kB 查看哈希值)

上传于 CPython 3.10 macOS 11.0+ ARM64

hussh-0.1.7-cp310-cp310-macosx_10_12_x86_64.whl (372.7 kB 查看哈希值)

上传于 CPython 3.10 macOS 10.12+ x86-64

hussh-0.1.7-cp39-none-win_amd64.whl (294.6 kB 查看哈希值)

上传于 CPython 3.9 Windows x86-64

hussh-0.1.7-cp39-none-win32.whl (271.3 kB 查看哈希值)

上传于 CPython 3.9 Windows x86

hussh-0.1.7-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.9 MB 查看哈希值)

上传于 CPython 3.9 manylinux: glibc 2.17+ x86-64

hussh-0.1.7-cp39-cp39-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.9 MB 查看哈希值)

上传于 CPython 3.9 manylinux: glibc 2.17+ ppc64le

hussh-0.1.7-cp39-cp39-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.6 MB 查看哈希值)

上传于 CPython 3.9 manylinux: glibc 2.17+ ARMv7l

hussh-0.1.7-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.2 MB 查看哈希值)

上传于 CPython 3.9 manylinux: glibc 2.17+ ARM64

hussh-0.1.7-cp39-cp39-macosx_11_0_arm64.whl (365.6 kB 查看哈希值)

上传于 CPython 3.9 macOS 11.0+ ARM64

hussh-0.1.7-cp39-cp39-macosx_10_12_x86_64.whl (373.6 kB 查看哈希值)

上传于 CPython 3.9 macOS 10.12+ x86-64

hussh-0.1.7-cp38-none-win_amd64.whl (294.6 kB 查看哈希值)

上传于 CPython 3.8 Windows x86-64

hussh-0.1.7-cp38-none-win32.whl (271.2 kB 查看哈希值)

上传于 CPython 3.8 Windows x86

hussh-0.1.7-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.9 MB 查看哈希值)

上传于 CPython 3.8 manylinux: glibc 2.17+ x86-64

hussh-0.1.7-cp38-cp38-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.9 MB 查看哈希值)

上传于 CPython 3.8 manylinux: glibc 2.17+ ppc64le

hussh-0.1.7-cp38-cp38-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.6 MB 查看哈希值)

上传于 CPython 3.8 manylinux: glibc 2.17+ ARMv7l

hussh-0.1.7-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.2 MB 查看哈希值)

上传于 CPython 3.8 manylinux: glibc 2.17+ ARM64

支持