Skip to main content

SSH config generator based on Ansible hosts yaml file

Project description

sshgen

SSH configuration generator based on your Ansible hosts YAML file.

Current version: v0.1.1

Table of Contents

TBD

Features

  1. Generates a config file to merge with your existing SSH configuration.
  2. Custom configuration for ssh-agent.
  3. Custom SSH aliases for quick connections.

Installation

Using pip

pip install --user git+https://github.com/pythoninja/sshgen@v0.1.1

Using pipx

pipx install git+https://github.com/pythoninja/sshgen@v0.1.1

Usage

Before using this tool, make sure you have an Ansible hosts.yml in your current working directory.

Consider the following example hosts.yml file, which defines 2 host groups with a total of 3 hosts:

group1: # host_group
  hosts:
    host1: # host
      ansible_host: 127.0.0.1
      ansible_user: root
      _meta:
        _auth_type: IdentityAgent
        _auth_path: ~/.1password/agent.sock
        _aliases: [ "base", "another-alias" ]

    host2:
      ansible_host: 127.0.0.2
      ansible_user: manager
      ansible_password:

group2:
  hosts:
    another_host1:
      ansible_host: 172.19.0.1
      ansible_user: postgres
      ansible_password:

To use sshgen, you can either invoke it as a Python module using python -m sshgen --help or directly use the command sshgen --help.

By default, sshgen looks for the hosts.yml file in your current working directory. To generate the SSH configuration, run the following command:

sshgen generate

After executing the command, you will see the following output:

[INFO] - Generated SSH config file was saved to /my_dir/config

Check the file contents cat /my_dir/config:

Host host1 base another-alias # group1
    HostName 127.0.0.1
    User root
    IdentityAgent ~/.1password/agent.sock

Host host2  # group1
    HostName 127.0.0.2
    User manager
    IdentityFile ~/.ssh/ssh_key
    IdentitiesOnly yes

Host another_host1  # group2
    HostName 172.19.0.1
    User postgres
    IdentityFile ~/.ssh/ssh_key
    IdentitiesOnly yes

Copy and insert the output into your ~/.ssh/config file. After that, you can use any of the defined aliases to SSH into the corresponding hosts. For example, running ssh base will connect you to the host with the IP address 127.0.0.1 as the root user and utilizing 1password as your SSH agent.

For more examples, please refer to the examples directory.

License

There are no specific requirements for usage and distribution. For more information, refer to the LICENSE.

Changelog

For the changelog, please see CHANGELOG.md.

Project details


Download files

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

Source Distribution

sshgen-0.1.1.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

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

sshgen-0.1.1-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

Details for the file sshgen-0.1.1.tar.gz.

File metadata

  • Download URL: sshgen-0.1.1.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.10.6 Linux/5.15.0-1040-azure

File hashes

Hashes for sshgen-0.1.1.tar.gz
Algorithm Hash digest
SHA256 9ccd8b6debc1fae28a1bb0f7cdaaab4cc876da80f06d86f6c55f6e73b30cc21c
MD5 53c24805f540e10148b8d1b494863c33
BLAKE2b-256 3e7f2591eddf237dbc31d44f292fe3443d4312f6e96b727e9f239004a6877ac6

See more details on using hashes here.

File details

Details for the file sshgen-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: sshgen-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 9.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.10.6 Linux/5.15.0-1040-azure

File hashes

Hashes for sshgen-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c3ba295db25f547e5fad05a82e9a79206e0702e39c3ba24ed1f5077ff4b2ea82
MD5 739dd626c110e12208b978910e2ef8a9
BLAKE2b-256 32d9009c322bddf61c9b6962a01c972439fb9decdb14ed003a11e66c89a20387

See more details on using hashes here.

Supported by

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