{ "info": { "author": "Alexandros Solanos", "author_email": "solanosalex@gmail.com", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 3" ], "description": "# Digital ocean -> ssh config\n\nDepends on https://github.com/koalalorenzo/python-digitalocean which can be installed with `pip3 install -U python-digitalocean`\n\nThis python 3 script will help you keep your ssh config in sync with your digital ocean droplets\n\n```bash\n$ python3 do_to_ssh_config.py production\n\n\u00b7 Reading /home/alex/.config/do_to_ssh_config/production.json\n\u00b7 Parsing /home/alex/.ssh/config\n\u00b7 Fetching droplets from DO\n\u00b7 Writing into your ssh config file\n\n\u2713 Done, 11 droplets synced\n```\n\n## Features\n\n* Supports different ssh keys for each droplet, depending on the DO tags of the droplet\n* Works with different configurations and can write in different sections of your ssh config\n\n## How to\n\n### Step 1: Create the json configuration file\nSave this at `~/.config/do_to_ssh_config/.json`, where `` is how you want to call it, e.g. `production` or `testing` or anything else. For this example I will use `production`.\n\n```json\n{\n \"token\": \"DIGITAL_OCEAN_READ_ONLY_TOKEN_HERE\",\n \"keys\": {\n \"tagToKey\": {\n },\n \"default\": {\n \"key\": \"common\",\n \"priority\": 0\n }\n },\n \"startMark\": \"# DO production\",\n \"endMark\": \"# /DO production\",\n \"hostPrefix\": \"do-prod-\"\n}\n```\n*Note*: This is the simplest possible configuration file that uses the same key for every droplet and the droplet name as `Host`, for more options, read on.\n\n1. Generate a new personal DO API read-only access token [here](https://cloud.digitalocean.com/account/api/tokens)\n2. `hostPrefix` is what prefix to add in the `Host` key in your ssh config for each droplet loaded through this configuration, can be anything you want\n\n### Step 2: Add the 2 marks in your ssh config\nThe above json configuration contains the `startMark` and `endMark`. These should be somewhere inside your ssh configuration and can be whatever you want (start with `#` for ssh config comments, though):\n```ssh\n# DO production\n# /DO production\n```\n\nBetween these 2 marks the script will **delete** everything and add the new entries. Be careful not to add your own hosts between these 2 marks.\n\n

\n \n

\n\n### Step 3: Run the script\n\n```bash\n$ python3 do_to_ssh_config.py production\n\n\u00b7 Reading /home/alex/.config/do_to_ssh_config/production.json\n\u00b7 Parsing /home/alex/.ssh/config\n\u00b7 Fetching droplets from DO\n\u00b7 Writing into your ssh config file\n\n\u2713 Done, 11 droplets synced\n```\n\nNow your ssh config will look like this:\n```ssh\n# DO production\nHost do-prod-control-center1517024146\n # control-center1517024146\n Hostname X.X.X.X\n IdentityFile ~/.ssh/common\n User user\nHost do-prod-control-center1517027030\n # control-center1517027030\n Hostname X.X.X.X\n IdentityFile ~/.ssh/common\n User user\n... 9 more entries\n# /DO production\n```\n\nIf you have autogenerated ugly `Host` names derived from the droplet names, you can make it work with the droplet tags instead; read on.\n\n## I want to use a different ssh key, not `common`!\n\n* Change the `keys.default.key` setting\n\n## I want to use a different ssh key per droplet tag!\n\n* Change the `keys.tagToKey` setting and add in it entries like:\n\n```json\n\"control-center\": {\n \"key\": \"cc_prv\",\n \"priority\": 7\n},\n\"consul-server\": {\n \"key\": \"cs_prv\",\n \"priority\": 6\n},\n\"postgres-master\": {\n \"key\": \"common\",\n \"priority\": 5\n}\n```\n\nThe final config will look like this:\n\n```json\n{\n \"token\": \"DIGITAL_OCEAN_READ_ONLY_TOKEN_HERE\",\n \"keys\": {\n \"tagToKey\": {\n \"control-center\": {\n \"key\": \"cc_prv\",\n \"priority\": 7\n },\n \"consul-server\": {\n \"key\": \"cs_prv\",\n \"priority\": 6\n },\n \"postgres-master\": {\n \"key\": \"common\",\n \"priority\": 5\n }\n },\n \"default\": {\n \"key\": \"common\",\n \"priority\": 0\n }\n },\n \"startMark\": \"# DO production\",\n \"endMark\": \"# /DO production\",\n \"hostPrefix\": \"do-prod-\"\n}\n```\n\n*Important*: A droplet can have more than 1 tag, that's why there's a field called `priority` there. In the above example, if a droplet has both the `control-center` and `consul-server` tags, it will use the key with the higher priority (here `control-center`). If a droplet has no tags or its tags do not appear in `tagToKey`, it will use the default key.\n\nFor the droplets that match a specific tag, now the `Host` in the ssh config will have the name of the tag, not the droplet name:\n\n```ssh\n# DO production\nHost do-prod-control-center\n # control-center1517024146\n Hostname X.X.X.X\n IdentityFile ~/.ssh/cc_prv\n User user\nHost do-prod-control-center2\n # control-center1517027030\n Hostname X.X.X.X\n IdentityFile ~/.ssh/cc_prv\n User user\n... more entries\n# /DO production\n```\n\nThis is convenient for large environments where the droplet names are autogenerated\n\n*Note*: The droplet name is still visible as a comment in the first line of each entry\n\n*Note*: As shown in the above example, if 2 or more droplets share the same tag, an ascending number is appended to the `Host` value.\n\nNow you can see everything easily using ssh's tab completion, and connect anywhere:\n```\n$ ssh do-prod- \n\ndo-prod-control-center do-prod-mongodb do-prod-load-balancer do-prod-nodejs2 do-prod-postgres-slave do-prod-blog\ndo-prod-control-center2 do-prod-landing-page do-prod-nodejs do-prod-postgres-master do-prod-redis \n```\n\n## I have production *and* testing and I work in 10 different companies!\n\nSimply create different configuration files under `~/.config/do_to_ssh_config/`, one for each use case of yours, like `production.json` and `testing.json`. It will be useful to have a different `hostPrefix` for each use case.\n\nAlso, add the different markings in your ssh config file, e.g.:\n\n```ssh\n# DO production\n# /DO production\n\n# DO testing\n# /DO testing\n```\n\nNow if you run\n```bash\n$ python3 do_to_ssh_config.py production\n```\nit will go on and read from `production.json` and write in the corresponding marking inside your ssh config. And if you run\n```bash\n$ python3 do_to_ssh_config.py testing\n```\nit will go on and read from `testing.json` and write in the corresponding marking.\n\n\n## Can I safely re-run the script any times I want?\n\nYes, provided that you haven't included any entries of yours between the markings you've specified in the configuration. Everything between the markings is deleted each time the script runs.\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/hytromo/digital-ocean-to-ssh-config", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "do-to-ssh-config", "package_url": "https://pypi.org/project/do-to-ssh-config/", "platform": "", "project_url": "https://pypi.org/project/do-to-ssh-config/", "project_urls": { "Homepage": "https://github.com/hytromo/digital-ocean-to-ssh-config" }, "release_url": "https://pypi.org/project/do-to-ssh-config/0.0.4/", "requires_dist": [ "python-digitalocean" ], "requires_python": "", "summary": "Combine DO droplets with your ssh configuration", "version": "0.0.4" }, "last_serial": 4257580, "releases": { "0.0.4": [ { "comment_text": "", "digests": { "md5": "e029744952640ef9f46ea0d3cee19a74", "sha256": "0bc87b502e455eb28c4c53c3d2c1d3b6ea2d4d8a871679c1a0b2fe9ce2af029f" }, "downloads": -1, "filename": "do_to_ssh_config-0.0.4-py3-none-any.whl", "has_sig": false, "md5_digest": "e029744952640ef9f46ea0d3cee19a74", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 5419, "upload_time": "2018-09-10T12:56:58", "url": "https://files.pythonhosted.org/packages/0d/0c/577a5c1cb31f2a12e0961c7df09087532c4b914334d40de434c6e0d8b9d7/do_to_ssh_config-0.0.4-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "3aa33a94b39fd06f5b406a31f17b4bd1", "sha256": "669dda332a88fd7d87383f64a8997a7c3b9f758b8394157415ae3814408f4c6d" }, "downloads": -1, "filename": "do_to_ssh_config-0.0.4.tar.gz", "has_sig": false, "md5_digest": "3aa33a94b39fd06f5b406a31f17b4bd1", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5398, "upload_time": "2018-09-10T12:57:00", "url": "https://files.pythonhosted.org/packages/d1/19/781e1440c00d97a22e1b4c9e0ce09fed1a8741ba46b6d38cc887fe86c7ed/do_to_ssh_config-0.0.4.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "e029744952640ef9f46ea0d3cee19a74", "sha256": "0bc87b502e455eb28c4c53c3d2c1d3b6ea2d4d8a871679c1a0b2fe9ce2af029f" }, "downloads": -1, "filename": "do_to_ssh_config-0.0.4-py3-none-any.whl", "has_sig": false, "md5_digest": "e029744952640ef9f46ea0d3cee19a74", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 5419, "upload_time": "2018-09-10T12:56:58", "url": "https://files.pythonhosted.org/packages/0d/0c/577a5c1cb31f2a12e0961c7df09087532c4b914334d40de434c6e0d8b9d7/do_to_ssh_config-0.0.4-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "3aa33a94b39fd06f5b406a31f17b4bd1", "sha256": "669dda332a88fd7d87383f64a8997a7c3b9f758b8394157415ae3814408f4c6d" }, "downloads": -1, "filename": "do_to_ssh_config-0.0.4.tar.gz", "has_sig": false, "md5_digest": "3aa33a94b39fd06f5b406a31f17b4bd1", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5398, "upload_time": "2018-09-10T12:57:00", "url": "https://files.pythonhosted.org/packages/d1/19/781e1440c00d97a22e1b4c9e0ce09fed1a8741ba46b6d38cc887fe86c7ed/do_to_ssh_config-0.0.4.tar.gz" } ] }