Python SSH Keys and Host Inventory
An unattended script needs a key with no passphrase, which sounds careless until you see what `authorized_keys` can restrict it to - a key that can run one command and nothing else. Then the other half: one inventory file that says what exists, so adding a host is one line rather than an edit to every script. Including the `ssh_config` mistake I made while writing this, which silently discards every specific setting.
Remote Hosts and CI/CD Guide 32 of 39 Intermediate
- Python3.14.4
- Control nodeUbuntu 26.04 LTS
- Managed hostsRHEL 10.0
- requests2.34.2
- paramiko5.0.0
- pytest9.1.1
- PyYAML6.0.3
- boto3 / botocore1.43.78
- TimeAbout 20 min
- Reviewed24 August 2026
Written against the versions above. `restrict` in authorized_keys needs OpenSSH 7.2 or later and is the sensible default - it turns off everything and lets you add back what you need. `paramiko.SSHConfig.from_path` needs paramiko 2.7.
| Server Name | IP Address | OS | Roles | CPU | RAM | HDD |
|---|---|---|---|---|---|---|
| RUNNER01 | 192.168.0.27 | Ubuntu 26.04 LTS | Control node - every script in this path runs here | 2 Core | 4 GB | 50 GB |
| RHCSA-A01 | 192.168.0.31 | RHEL 10.0 | Managed host - reached over SSH from the control node | 2 Core | 4 GB | 50 GB |
| RHCSA-B01 | 192.168.0.33 | RHEL 10.0 | Second managed host - so an inventory has more than one row | 2 Core | 4 GB | 50 GB |
Before you start
- guide 31 - the connection this configures.
- guide 13 - the inventory format.
- guide 25 - a credential is a credential.
-
A key made for one job
-
The key on disk
-
What a key is allowed to do
-
And the same key with no restriction
-
An inventory, in one file
-
An inventory that is wrong
-
The config file ssh already reads, and the trap in it
-
And using it to connect
-
A key with a passphrase
-
Or let an agent hold it
-
The inventory driving a real loop
-
And a service that is not there