Use this when automating SSH from Python.
SSH Automation · Python Automation
SSH automation in Python uses Paramiko for raw SSH, Netmiko or Scrapli for network devices and Fabric for servers, sending commands and handling prompts, keys and timeouts.
1. SSH automation with paramiko, netmiko, fabric, asyncssh.
2. Verify host keys.
3. Key-based auth from vault.
4. Timeouts and error handling.
5. Prefer APIs when available.
script → SSH (verified host key) → commands → parsed output
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 Common mistakes Narrow the fault
- Screen-scraping without parsing (TextFSM/Genie).
- Not saving the configuration after changes.
- Disabling host-key checking permanently.
Evidence · 1 on this Topic
Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.
- Paramiko for raw SSH, Netmiko/Scrapli for network devices, Fabric for servers.
- Handle prompts and timeouts.
- Use SSH keys.
python3 -c 'import paramiko'— library present- Host key verification (no AutoAddPolicy in prod) — security
- Netmiko/Fabric for devices/hosts — libraries
ReferenceWhy it matters1 section · depth on demand
What it is
SSH automation logs in to devices and runs commands or pushes config: Netmiko and Scrapli for network CLIs, Paramiko for raw SSH. Prefer APIs where the device has one.
ReferenceImportant terms & boundaries2 sections · depth on demand
How it works
Netmiko and Scrapli open an SSH session, detect the prompt, disable paging and send commands, returning the raw text; with TextFSM/TTP/Genie templates the output becomes structured data. Configuration changes go through config mode and should be followed by a read-back and write memory (or copy run start).
Example
from netmiko import ConnectHandler
with ConnectHandler(device_type="cisco_ios", host=h, username=u, password=p) as c:
out = c.send_command("show ip interface brief", use_textfsm=True)
c.send_config_set(["interface Gi0/1", "description uplink"])
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Authoritative/upstream documentation reviewed for bounded claims in Python Automation > SSH Automation. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://docs.python.org/3/ · confidence 94%What changed and what may be affected
Recent technical edits are separated from ordinary page timestamps. Relationship impact is advisory: it identifies nearby canonical references to review, not automatic breakage.