🔐 AutoSec - Python & SSH Automation

Python-based SSH automation to keep your network configuration fast, repeatable, and secure.

What does the Python script do?

This Python-based automation script manages SSH and COM connections, as well as configuration tasks, across network devices. It standardizes settings, reduces manual command-line interface operations, and enables repeatable workflows for switches, routers, and servers, functioning similarly to SCCM Configuration Manager for Windows.

🔑Multiple Authentication

Use passwords or SSH keys with libraries like paramiko or netmiko, giving you flexible authentication per device or environment.

🌐Multi-Host Management

Loop through multiple hosts from a Python list or inventory file, applying the same logic to production, staging, and lab devices with a single script.

🚇Consistent Configs

Send standardized configuration commands over SSH to switches, routers, and servers, keeping network behavior predictable and documented in code.

⚙️Rapid Deployment

Push updates, patch changes, or new settings to dozens of devices in minutes instead of hours of manual CLI sessions.

🤖Automation Friendly

Integrate Python scripts into CI/CD pipelines, cron jobs, or orchestration tools to schedule checks and configuration tasks automatically.

🔧Error Reduction

Centralize commands and logic in one script, reducing the chance of mistyped commands or inconsistent setups between devices.

How to Use a Python SSH Automation Script

1. Define your device settings:

import netmiko device = { "device_type": "cisco_ios", "ip": "192.168.1.100", "username": "admin", "password": "your_password", "secret": "enable_password", }

2. Connect and run commands:

from netmiko import ConnectHandler connection = ConnectHandler(**device) connection.enable() commands = [ "hostname AutoSec-SW1", "interface vlan 1", "ip address 192.168.1.5 255.255.255.0", "no shutdown", ] output = connection.send_config_set(commands) print(output) connection.save_config() connection.disconnect()

3. Extend to multiple devices:

devices = [device1, device2, device3] for dev in devices: with ConnectHandler(**dev) as conn: conn.enable() conn.send_config_set(commands) conn.save_config() print(f"Configured {dev['ip']}")

⚠️ Security Notice

Real passwords or private keys should not be hard-coded in Python scripts. Instead, utilize environment variables, encrypted vaults, or secret managers. Restrict automation to specific hosts and users, and conduct thorough testing in a laboratory environment prior to deployment on production devices.

Why Use Python for SSH Automation?

  • 🔧 Repeatable Commands: Storing standardized configurations in Python lists and functions enables consistent application of changes without manual repetition.
  • 🌍 Scales Across Environments: Python automation can target development, testing, and production environments by utilizing different device lists or credentials while maintaining consistent core logic.
  • 🚇 Comprehensive Access Control: SSH tunnels, jump hosts, and role-based accounts can be managed centrally through a single Python entry point.
  • 🔑 Robust Key Management Key-based authentication is preferred over password-based methods, and automated routines can facilitate regular key rotation as required.
  • 🤖 Integrates Everywhere: Python scripts can run on laptops, jump boxes, CI pipelines, or management servers, giving you flexible control over where and how automation executes.

Ready to Get Started?

Build a simple Python SSH script, test it against a lab switch or router, and then expand it into a reusable tool for your entire AutoSec environment.

View Usage Guide