{"id":18010829,"url":"https://github.com/yokawasa/azure-ssh-config","last_synced_at":"2025-03-26T14:32:14.348Z","repository":{"id":57413558,"uuid":"69807329","full_name":"yokawasa/azure-ssh-config","owner":"yokawasa","description":"A command to generate SSH config file from Azure ARM VM inventry in subscription","archived":false,"fork":false,"pushed_at":"2022-05-21T07:43:55.000Z","size":26,"stargazers_count":9,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-21T23:33:49.455Z","etag":null,"topics":["azure","completion","python","service-principal","ssh","ssh-config"],"latest_commit_sha":null,"homepage":"https://github.com/yokawasa/azure-ssh-config","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yokawasa.png","metadata":{"files":{"readme":"README.md","changelog":"ChangeLog.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-10-02T16:14:19.000Z","updated_at":"2023-03-29T21:04:28.000Z","dependencies_parsed_at":"2022-08-27T23:02:13.942Z","dependency_job_id":null,"html_url":"https://github.com/yokawasa/azure-ssh-config","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yokawasa%2Fazure-ssh-config","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yokawasa%2Fazure-ssh-config/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yokawasa%2Fazure-ssh-config/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yokawasa%2Fazure-ssh-config/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yokawasa","download_url":"https://codeload.github.com/yokawasa/azure-ssh-config/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245670893,"owners_count":20653447,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["azure","completion","python","service-principal","ssh","ssh-config"],"created_at":"2024-10-30T02:15:27.761Z","updated_at":"2025-03-26T14:32:14.090Z","avatar_url":"https://github.com/yokawasa.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Azure SSH Config (azuresshconfig)\n\nGenerate SSH config file from Azure ARM VM inventry in subscription\n\n## Introduction\n\nazuresshconfig is a simple script that collects Azure ARM Virtual Machine(VM) inventry in subscription and generate a SSH config entries to be appended to $HOME/.ssh/config (the file is newly created if no exist). This is like an Azure version of [ec2ssh](https://github.com/mirakui/ec2ssh) or [aws-ssh-config](https://github.com/gianlucaborello/aws-ssh-config) that strongly inspired this initiative. This would be very helpful when you manage lots of VMs that have dynamic IP assignment settings and need frequent VM up-and-down operations for them which causes the change of IPs assigned to VMs. In such a case, azuresshconfig will definitly make your SSH life easy.\n\n\n## Installation\n\n```\npip install azuresshconfig\n```\n\n## Configuration\n\nGenerate client profile template file by executing the following command.\n\n```\nazuresshconfig --init\n```\n\nConfigure the client profile file, in which you add your service principal account info to access your resources in Azure via Azure APIs.\n\n```\nvi $HOME/.azure/azuresshconfig.json\n\n{\n    \"subscription_id\": \"\u003cYOUR SUBSCRIPTION ID\u003e\",\n    \"client_id\": \"\u003cYOUR APPLICATION CLIENT IP\u003e\",\n    \"client_scret\": \"\u003cYOUR APPLICATION CLIENT SCRET\u003e\",\n    \"tenant_id\": \"\u003cYOUR TENANT ID\u003e\"\n}\n```\n\nFor those who don't know how to create service principal, there is a great instruction: [Use Azure CLI to create a service principal to access resources](https://azure.microsoft.com/en-us/documentation/articles/resource-group-authenticate-service-principal-cli/). If you have Azure CLI 2.0 command installed on your evironment, you can create your service principal and configure its access to your azure resources with a single command 'az ad sp create-for-rbac'. \n\nSuppose your app id uri is 'http://unofficialism.info' and role you want to give for the app is 'Reader', you can create your service principal like this:\n\n```\naz ad sp create-for-rbac -n \"http://unofficialism.info\" --role reader\n```\n\nYou will get an output like this, and with them you can fill out the client profile file:\n\n```\n{\n  \"appId\": \"c36x4b4f-bef6-422e-bd3b-65057e7ab065\",        # -\u003e client_id in client profile file\n  \"displayName\": \"azure-cli-2017-03-30-05-16-59\",         \n  \"name\": \"http://unofficialism.info\",\n  \"password\": \"32126d32-7453-4053-3353-c420d4ffef2e\",     # -\u003e client_scret in client profile file\n  \"tenant\": \"72f988bf-86f1-41af-91cb-2d7cd011db47\"        # -\u003e tenant_id in client profile file\n}\n```\n\nFor the detail of service principal role, please refer to [Built-in roles for Azure Role-Based Access Control](https://docs.microsoft.com/en-us/azure/active-directory/role-based-access-built-in-roles).\n\n\n## Usage\n\nAssuming all required packages are installed and rightly configured, you're ready to run azuresshconfig\n\n```\nazuresshconfig --help\n\nusage: azuresshconfig.py [-h] [--version] [--init] [--profile PROFILE]\n                         [--output OUTPUT] [--user USER]\n                         [--identityfile IDENTITYFILE] [--private]\n                         [--resourcegroups RESOURCEGROUPS] [--params PARAMS]\n\nThis program generates SSH config from Azure ARM VM inventry in subscription\n\noptional arguments:\n  -h, --help            show this help message and exit\n  --version             show program's version number and exit\n  --init                Create template client profile at\n                        $HOME/.azure/azuresshconfig.json only if there is no\n                        existing one\n  --profile PROFILE     Specify azure client profile file to use\n                        ($HOME/.azure/azuresshconfig.json by default)\n  --output OUTPUT       Specify ssh config file path ($HOME/.ssh/config by\n                        default). Or specify \"stdout\" if you want to print its\n                        output to STDOUT\n  --user USER           SSH username to use for all hosts\n  --identityfile IDENTITYFILE\n                        SSH identity file to use for all hosts\n  --private             Use private IP addresses (Public IP is used by\n                        default)\n  --resourcegroups RESOURCEGROUPS\n                        A comma-separated list of resource group to be\n                        considered for ssh-config generation (all resource\n                        groups by default)\n  --params PARAMS       Any ssh-config params you want to add with query-\n                        string format: key1=value1\u0026key2=value2\u0026...\n```\n\n\n### 1. Running with no optional args\n```\nazuresshconfig\n```\n\nEach host entry in output ssh-config file is simple like this:\n\n```\ncat ~/.ssh/config\n\n### AZURE-SSH-CONFIG BEGIN ###\n\nHost myvm1\n    HostName 40.74.124.30\n\nHost myvm2\n    HostName 40.74.116.134\n....\n\n### AZURE-SSH-CONFIG END ###\n```\n\n\n### 2. Running with user, output, and identity file options\n```\nazuresshconfig --user yoichika --output /mypath/config --identityfile ~/.ssh/id_rsa\n```\n\nUser and identify file are added to each host entry in output ssh-config file:\n\n```\ncat /mypath/config\n\n### AZURE-SSH-CONFIG BEGIN ###\n\nHost myvm1\n    HostName 40.74.124.30\n    IdentityFile ~/.ssh/id_rsa\n    User yoichika\n\nHost myvm2\n    HostName 40.74.116.134\n    IdentityFile ~/.ssh/id_rsa\n    User yoichika\n....\n\n### AZURE-SSH-CONFIG END ###\n```\n\n### 3. Running with user, identity file, and resource group options\n```\nazuresshconfig --user yoichika \\\n                --identityfile ~/.ssh/id_rsa \\\n                --resourcegroups mygroup1,mygroup2\n```\n\nOnly host entry that belong to specified resource group are added in ssh-config\n\n### 4. Running with user, identity file, and additional ssh-config params\n```\nazuresshconfig.py --user yoichika \\\n                --identityfile ~/.ssh/id_rsa \\\n                --params \"Port=2222\u0026Protocol=2\u0026UserKnownHostsFile=~/.ssh/known_hosts\u0026ForwardAgent=yes\"\n```\n\nAdditional ssh-config params specified by --params are added to an output ssh-config file like this:\n\n```\ncat ~/.ssh/config\n\n### AZURE-SSH-CONFIG BEGIN ###\n\nHost myvm1\n    HostName 40.74.124.30\n    IdentityFile ~/.ssh/id_rsa\n    User yoichika\n    Port 2222\n    Protocol 2\n    UserKnownHostsFile ~/.ssh/known_hosts\n    ForwardAgent yes\n\nHost myvm2\n    HostName 40.74.116.134\n    IdentityFile /home/yoichika/.ssh/id_rsa\n    User yoichika\n    Port 2222\n    Protocol 2\n    UserKnownHostsFile ~/.ssh/known_hosts\n    ForwardAgent yes\n....\n\n### AZURE-SSH-CONFIG END ###\n```\n\n## Docker (Dockerfile)\n\nNow docker image for azuresshconfig is available (yoichikawasaki/azuresshconfig). The image is based on Alpine Linux image, and contains Python2.7, pip, azuresshconfig Python packages and its prerequisite libraries.\n\nDownload size of this image is only 155 MB\n```\n$ docker images azuresshconfig\nREPOSITORY                          TAG                 IMAGE ID            CREATED             SIZE\nazuresshconfig                     latest              7488bef4343f        7 minutes ago       155 MB\n```\n\n### Usage Example\n\n```bash\n$ docker run -v $HOME:/root --rm -it yoichikawasaki/azuresshconfig \\\n    --output stdout --user yoichika --identityfile ~/.ssh/id_rsa \u003e $HOME/.ssh/config\n```\nor you can build from Dockerfile and run your local images like this:\n\n```bash\n$ docker build -t azuresshconfig .\n$ docker run -v $HOME:/root --rm -it azuresshconfig \\\n     --output stdout --user yoichika --identityfile ~/.ssh/id_rsa \u003e $HOME/.ssh/config\n```\n\n## Shell Completion\n### Bash\nBash completion will work by loading bash/[azuresshconfig_completion.bash](https://github.com/yokawasa/azure-ssh-config/blob/master/bash/azuresshconfig_completion.bash). In order to load azuresshconfig_completion.bash, you can do like this\n```\n# copy this under either of following directories\ncp azuresshconfig_completion.bash (/etc/bash_completion.d | /usr/local/etc/bash_completion.d | ~/bash_completion.d)\n\n# or append 'source /path/to/azuresshconfig_completion.bash' to .bashrc like this\necho 'source /path/to/azuresshconfig_completion.bash' \u003e\u003e .bashrc\n```\n\nOnce azuresshconfig_completion.bash is loaded, Bash completion will work this:\n```\n$ azuresshconfig -[tab]\n-h                --identityfile    --params          --profile         --user\n--help            --init            --private         --resourcegroups\n\n$ azuresshconfig --i[tab]\n--identityfile  --init\n\n$ azuresshconfig --p[tab]\n--params   --private  --profile\n\n$ azuresshconfig --user [tab]\n$ azuresshconfig --user \u003cssh_user\u003e\n$ azuresshconfig --user \u003cssh_user\u003e --identityfile [tab]\n$ azuresshconfig --user \u003cssh_user\u003e --identityfile \u003cssh_identity_file\u003e\n```\n\n## Todo\n\n* Support zsh Completion (Hopefully support it soon)\n\n## Issues\n\n* [Kown Issues and resolutions](Issues.md)\n* [Current Issues, bugs, and requests](https://github.com/yokawasa/azure-ssh-config/issues)\n\n## Change log\n\n* [Changelog](ChangeLog.md)\n\n## Links\n\n* https://pypi.python.org/pypi/azuresshconfig/\n* http://unofficialism.info/posts/azuresshconfig/\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/yokawasa/azure-ssh-config.\n\n## Copyright\n\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003ctd\u003eCopyright\u003c/td\u003e\u003ctd\u003eCopyright (c) 2016- Yoichi Kawasaki\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003eLicense\u003c/td\u003e\u003ctd\u003eMIT\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyokawasa%2Fazure-ssh-config","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyokawasa%2Fazure-ssh-config","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyokawasa%2Fazure-ssh-config/lists"}