Skip to main content

Generate SSH config file from Azure ARM VM inventry in subscription

Introduction

azuresshconfig 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 or 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.

Installation

pip install azuresshconfig

Configuration

Generate client profile template file by executing the following command.

azuresshconfig --init

Configure the client profile file, in which you add your service principal account info to access your resources in Azure via Azure APIs.

vi $HOME/.azure/azuresshconfig.json

{
    "subscription_id": "<YOUR SUBSCRIPTION ID>",
    "client_id": "<YOUR APPLICATION CLIENT IP>",
    "client_scret": "<YOUR APPLICATION CLIENT SCRET>",
    "tenant_id": "<YOUR TENANT ID>"
}

For 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. 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’.

Suppose 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:

az ad sp create-for-rbac -n "http://unofficialism.info" --role reader

You will get an output like this, and with them you can fill out the client profile file:

{
  "appId": "c36x4b4f-bef6-422e-bd3b-65057e7ab065",        # -> client_id in client profile file
  "displayName": "azure-cli-2017-03-30-05-16-59",
  "name": "http://unofficialism.info",
  "password": "32126d32-7453-4053-3353-c420d4ffef2e",     # -> client_scret in client profile file
  "tenant": "72f988bf-86f1-41af-91cb-2d7cd011db47"        # -> tenant_id in client profile file
}

For the detail of service principal role, please refer to Built-in roles for Azure Role-Based Access Control.

Usage

Assuming all required packages are installed and rightly configured, you’re ready to run azuresshconfig

``` azuresshconfig –help

usage: azuresshconfig.py [-h] [–version] [–init] [–profile PROFILE] [–output OUT

Release files for azuresshconfig 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for azuresshconfig 0.3.0
File Size Uploaded
azuresshconfig-0.3.0.tar.gz 11.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for azuresshconfig 0.3.0
File Interpreter ABI Platform
azuresshconfig-0.3.0-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 51.3 kB

Release files / azuresshconfig-0.3.0.tar.gz

Download URL azuresshconfig-0.3.0.tar.gz
Size 11.4 kB
Tags Source
SHA-256 checksum
How to use checksums
39e4df8ecbabc1751c124a29a7440b06f3a14585d0943cf04163b6a79358d4da
BLAKE2b-256 checksum
How to use checksums
f81ceacb81651f25db62c23f73b1e02fde5329b9bb6cdefb0a92dc07ce012742
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / azuresshconfig-0.3.0-py2.py3-none-any.whl

Download URL azuresshconfig-0.3.0-py2.py3-none-any.whl
Size 39.9 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
40868e5b3c1d81b30bd144972b5a7e90e9b6285e4b36ff7140d0aeb69404bfee
BLAKE2b-256 checksum
How to use checksums
3aeef0a55d8c45d796d7ba8244821cdc8635612ee8daafdcc86f59767a728fec
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page