Skip to main content

sshc

SSH config and Ansible inventory from one host database.

sshc stores your servers in a JSON database under ~/.ssh, then generates OpenSSH config and Ansible inventory from that single source of truth. Works on Linux and Windows.

License: MIT

Features

  • One JSON DB for all hosts (names, IPs, users, keys, groups, comments).
  • DB metadata and SHA-256 integrity checksum on the hosts payload.
  • Generate sshc_ssh_config and sshc_ansible_inventory.json (or YAML).
  • sshc status — check integrity, drift vs generated files, missing keys.
  • sshc list — alias of read; optional verbose metadata output.
  • Optional Include in your default ~/.ssh/config so ssh <host> works without -F.
  • Safe generate — confirms before overwriting existing artifacts (-y to skip).

Installation

pip3 install sshc --upgrade

From source (development):

git clone https://github.com/fahadahammed/sshc.git
cd sshc
poetry install
poetry run sshc --version

Release notes: CHANGELOG.md.

Quick start

sshc init
sshc insert --name web1 --host 192.168.0.10 --user ubuntu --groups web prod
sshc generate
sshc list
sshc status

Use generated files:

ssh -F ~/.ssh/sshc_ssh_config web1
ansible -i ~/.ssh/sshc_ansible_inventory.json all --list-hosts

On Windows (PowerShell):

ssh -F $env:USERPROFILE\.ssh\sshc_ssh_config web1

Default paths

Artifact Path
Host DB <home>/.ssh/sshc_db.json
SSH config (generated) <home>/.ssh/sshc_ssh_config
Ansible inventory <home>/.ssh/sshc_ansible_inventory.json
OpenSSH default config <home>/.ssh/config (optional Include only)

<home> is your user profile directory ($HOME or %USERPROFILE%).

Commands

Command Description
init Create or upgrade the host DB (adds metadata to legacy files).
insert Add a host (unique name; skipped if duplicate).
update Change only fields you pass; insert if name is new.
delete Remove a host by name.
read / list Show hosts; --verbose yes includes DB metadata.
generate Rebuild SSH config and Ansible inventory from the DB.
status Health check; --json for automation.

Global: sshc --version, sshc --help.

Most subcommands accept --destination, --dbfile, and generate/status also accept --configfile / --inventoryfile.

init

Creates { "meta": {...}, "hosts": [] }. If the file already exists as a legacy JSON array, init upgrades it in place and keeps existing hosts.

sshc init

insert

sshc insert --name myserver --host 10.0.0.5 --user deploy \
  --port 22 --groups app staging --comment "staging app"

Groups are space-separated. Default user is root; default key path is <home>/.ssh/id_rsa.

generate

Rebuilds artifacts from the DB (full replace of generated content).

sshc generate
sshc generate -y
sshc generate --include-default-config
sshc generate --filetype yaml --inventoryfile ~/.ssh/sshc_ansible_inventory.yml
  • Confirmation: if SSH config or inventory already have content, you are prompted (Overwrite? [y/N]:). Use -y / --yes in scripts.
  • Include in default SSH config: --include-default-config adds a managed block to <home>/.ssh/config pointing at sshc_ssh_config so you can run ssh <hostname> without -F. Your main config is not overwritten—only an Include block is added or updated.
  • Prefer sshc_ssh_config over writing directly to config so personal SSH settings stay separate.

status

sshc status
sshc status --json

Exit code 0 when healthy (warnings allowed); 1 when regeneration is required or integrity fails.

update / delete / read

sshc update --name myserver --port 2222
sshc delete --hostname myserver
sshc list --verbose yes

Example output

Generated SSH config (excerpt)
# Generated At: 2023-01-24 11:35:25.885044
# sshc Version: 3.0.0

# -- <
Host server1
HostName 192.168.0.100
Port 22
User ubuntu
IdentityFile /home/user/.ssh/id_rsa
LogLevel INFO
Compression yes
# Comment: Personal Server: ONE
# -- >
Generated Ansible inventory (excerpt)
{
  "all": {
    "hosts": {
      "server1": {
        "ansible_host": "192.168.0.100",
        "ansible_port": 22,
        "ansible_user": "ubuntu",
        "ansible_ssh_private_key_file": "/home/user/.ssh/id_rsa"
      }
    },
    "children": {
      "personal": { "hosts": { "server1": null } }
    }
  },
  "others": {
    "generated_at": "2023-01-24 11:35:25.885044",
    "sshc_version": "3.0.0"
  }
}

Requirements

  • Runtime: Python 3.7+, PyYAML (installed with the package).
  • Platforms: Linux and Windows for sshc itself; OpenSSH and Ansible are separate installs used to consume generated files.

Contributing

Contributions are welcome—bug reports, docs, tests, and features.

  1. Fork the repository and create a branch from development (not main).
  2. Set up locally: poetry install, then poetry run python -m unittest tests/basic-function-test.py.
  3. Change the smallest scope that fixes the issue; match existing style in src/sshc.py.
  4. Document user-visible behavior in README.md and add an entry under [Unreleased] in CHANGELOG.md.
  5. Open a pull request to development with a clear description and how you tested (OS, commands run).

Maintainer-oriented design notes live in the Context/ directory (architecture, CLI, data model, gotchas).

Thank you for helping improve sshc.

Author

Fahad Ahammed — DevOps enthusiast, Dhaka, Bangladesh.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sshc-3.1.0.tar.gz (17.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sshc-3.1.0-py3-none-any.whl (16.1 kB view details)

Uploaded Python 3

File details

Details for the file sshc-3.1.0.tar.gz.

File metadata

  • Download URL: sshc-3.1.0.tar.gz
  • Upload date:
  • Size: 17.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.4.1 CPython/3.14.6 Linux/6.17.0-1020-azure

File hashes

Hashes for sshc-3.1.0.tar.gz
Algorithm Hash digest
SHA256 a1f3b7470bdec0ed8e4bebff918258a8becff6b10960fc80cd112a16c9dcf221
MD5 b45b748e4d4da3a362ef315995cf948b
BLAKE2b-256 9474879174271dccc66915a9af834ae8a3b420c82891eba2e8cecc93c9d9607d

See more details on using hashes here.

File details

Details for the file sshc-3.1.0-py3-none-any.whl.

File metadata

  • Download URL: sshc-3.1.0-py3-none-any.whl
  • Upload date:
  • Size: 16.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.4.1 CPython/3.14.6 Linux/6.17.0-1020-azure

File hashes

Hashes for sshc-3.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8c6aa307d4179be7333d17f9ab1a709a80526ec30157f73f91d63c8049182cb8
MD5 0314978ef35c09bfc2ca13a104a281c0
BLAKE2b-256 0dd728be41458f99b789436267f783147c638bf44eec3a1ce000c36fe4d59140

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

3.1.0 This release

2 files

3.0.0

2 files

2.0.1

2 files

2.0.0

2 files

1.0.0

2 files

0.9.0

2 files

0.8.0

2 files

0.7.0

2 files

0.6.0

2 files

0.5.0

2 files

0.4.0

2 files

0.3.0

2 files

0.2.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page