{"id":49081101,"url":"https://github.com/stan-smith/ssh_key_management","last_synced_at":"2026-04-20T13:14:16.214Z","repository":{"id":268720230,"uuid":"905259243","full_name":"stan-smith/ssh_key_management","owner":"stan-smith","description":"Ansible ssh_key_management","archived":false,"fork":false,"pushed_at":"2024-12-31T11:28:55.000Z","size":30,"stargazers_count":5,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-03-30T16:42:06.730Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stan-smith.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-12-18T13:22:45.000Z","updated_at":"2025-10-31T19:10:59.000Z","dependencies_parsed_at":"2024-12-18T14:39:49.658Z","dependency_job_id":"fa78acff-6bca-4e9d-8096-a6594cd6b02b","html_url":"https://github.com/stan-smith/ssh_key_management","commit_stats":null,"previous_names":["xkz0/ssh_key_management","stan-smith/ssh_key_management"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/stan-smith/ssh_key_management","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stan-smith%2Fssh_key_management","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stan-smith%2Fssh_key_management/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stan-smith%2Fssh_key_management/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stan-smith%2Fssh_key_management/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stan-smith","download_url":"https://codeload.github.com/stan-smith/ssh_key_management/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stan-smith%2Fssh_key_management/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32048565,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-20T11:35:06.609Z","status":"ssl_error","status_checked_at":"2026-04-20T11:34:48.899Z","response_time":94,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-04-20T13:14:15.717Z","updated_at":"2026-04-20T13:14:16.195Z","avatar_url":"https://github.com/stan-smith.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"### Easy Inventory Key Rotation For Ansible\n##### The problem\nI manage 400+ devices, nearly all of them are connected via cellular modems, and this means that a lot of them go offline.\nI needed a solution where I could implement ansible-pull rather than push to account for the fact that half of my units might be offline either due to poor coverage or just not being deployed.\nAs such I needed to allow for two way communication between the ansible server and the devices it was controlling, and make sure that that was secure.\nI needed the ability to push a playbook that creates a cron job to then perform the ansible pull. \n\n##### The solution\nSo this script lets me input a file containing a one per line listing of all the hostnames in my Tailscale network, and my ansible inventory.\nYou need to have a list of hosts in a format ansible will recognise i.e:\n```\n192.168.0.1\nmyhost.hostname.example\nhost-001\n```\n# First time setup:\nMake sure you define these variables in the .sh file, I'll probably change this to a menu prompt at some point:\n```\nKEY_DIR=\"WHERE THE KEYS WILL BE STORED\"\nUSER=\"REMOTE USER\"\nGIT_USER=\"GIT USER ON SERVER\"\nINVENTORY_FILE=\"INVENTORY.YAML\"\nHOSTS_FILE=\"LIST OF HOSTNAMES\"\n```\n\nYou also need an Ansible inventory that it can use to access the devices, make sure you specify the username for the account you're connecting to the machine with (whether this is a provisioning/admin account or something) and the authentication method (ssh private key or password) within the inventory.\n\nIt then generates a unique ssh private/public key for each device and saves that to the specified users directory on the ansible server, it then pushes that private and public key pair to the remote device.\n\nI know it's not best practice to move private keys, but this is the best solution I could come up with, and removes the use of hardcoded credentials/predicatable passwords.\n\nYou can easily change all the ssh keys for the devices by just re-running the script.\n\nThe reason for the temporary playbook is if you have 400+ open ssh connections inevitably some will timeout, so it's just more reliable to do it one by one, it has the same result.\n\nThe script also generates a list of units it wasn't able to touch, so if you need to go back and do those ones, you can just change out the hosts file to target them.\n\nThe key is added to authorized hosts on the specified user on both the remote and ansible server to enable two way comms using the same key.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstan-smith%2Fssh_key_management","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstan-smith%2Fssh_key_management","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstan-smith%2Fssh_key_management/lists"}