Configs2026年5月24日·1 分钟阅读

Paramiko — SSH Protocol Implementation for Python

A pure-Python implementation of the SSHv2 protocol providing both client and server functionality for secure remote command execution, file transfers, and port forwarding.

Agent 就绪

这个资产可以被 Agent 直接读取和安装

TokRepo 同时提供通用 CLI 命令、安装契约、metadata JSON、按适配器生成的安装计划和原始内容链接,方便 Agent 判断适配度、风险和下一步动作。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
Paramiko Overview
通用 CLI 安装命令
npx tokrepo install fc8cf2ba-578c-11f1-9bc6-00163e2b0d79

Introduction

Paramiko is the foundation of SSH automation in Python. It implements the SSHv2 protocol entirely in Python using cryptography primitives, making it portable across platforms. Tools like Fabric, Ansible, and sshuttle depend on Paramiko for their SSH transport layer.

What Paramiko Does

  • Establishes SSH connections with password, public key, or agent-based authentication
  • Executes remote commands and captures stdout, stderr, and exit status
  • Transfers files via SFTP with put, get, and directory operations
  • Creates SSH tunnels for local and remote port forwarding
  • Implements both SSH client and server roles in pure Python

Architecture Overview

Paramiko models the SSH protocol as a Transport (encrypted channel), on top of which you open Channels for shell sessions, command execution, or SFTP subsystems. The Transport handles key exchange, encryption (AES, ChaCha20), and MAC verification. An SSHClient class wraps common operations (connect, exec_command, open_sftp) for convenience.

Self-Hosting & Configuration

  • Install via pip: pip install paramiko
  • Depends on the cryptography library for all crypto operations
  • Load host keys from ~/.ssh/known_hosts or set a custom policy for verification
  • Use SSH agent forwarding by connecting to the system SSH agent via paramiko.Agent
  • Configure connection timeouts, banner timeouts, and keepalive intervals on the Transport

Key Features

  • Pure Python: runs on any platform without compiled SSH binaries
  • Full SFTP client with file read/write, directory listing, stat, chmod, and rename
  • SSH tunnel support for both local-to-remote and remote-to-local port forwarding
  • Ed25519, RSA, ECDSA, and DSA key support for authentication
  • Gateway/jump host support for connecting through bastion servers via ProxyCommand

Comparison with Similar Tools

  • Fabric — high-level SSH task runner built on top of Paramiko; Paramiko is the lower-level transport
  • asyncssh — async SSH library for asyncio; Paramiko is synchronous but more widely deployed
  • subprocess + ssh — shells out to the ssh binary; Paramiko keeps everything in-process with Python objects
  • libssh2 (via pylibssh2) — C-based SSH; Paramiko is pure Python and easier to install but slower for bulk transfers

FAQ

Q: Is Paramiko secure for production use? A: Yes. It uses the well-audited cryptography library for all crypto operations and supports modern algorithms like Ed25519 and ChaCha20-Poly1305.

Q: How do I use SSH keys instead of passwords? A: Pass key_filename to connect(), or load keys from an SSH agent. Paramiko supports PEM, OpenSSH, and PKCS8 key formats.

Q: Can Paramiko transfer entire directories? A: The SFTP client operates on individual files. For directory transfers, walk the remote directory tree with listdir_attr and transfer files individually, or use a higher-level tool like Fabric.

Q: Does Paramiko support connection pooling? A: Not built-in. Open multiple channels on a single Transport for multiplexed operations over one TCP connection, which is more efficient than multiple connections.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产