Pcornel
Automation · Python Automation

SSH Automation

Cheat sheet · https://pcornel.dk/topic.php?topic=5271

Back to the Topic

Answer

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.

Remember

  • Paramiko for raw SSH, Netmiko/Scrapli for network devices, Fabric for servers.
  • Handle prompts and timeouts.
  • Use SSH keys.

First checks

  • python3 -c 'import paramiko' — library present
  • Host key verification (no AutoAddPolicy in prod) — security
  • Netmiko/Fabric for devices/hosts — libraries

Verify in this order

script → SSH (verified host key) → commands → parsed output

Where it usually breaks

Input/desired state → request accepted → job/task terminal status → target object read-back → effective runtime state → original workload → regression/rollback readiness.

Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=5271

Confirmation

Confirm action

Continue?