HOWTO: Automatically import your public SSH keys into LXD Instances

Dustin Kirkland

Dustin Kirkland

on 25 February 2017

Just another reason why LXD is so awesome…

You can easily configure your own cloud-init configuration into your LXD instance profile.

In my case, I want cloud-init to automatically ssh-import-id kirkland, to fetch my keys from Launchpad.  Alternatively, I could use gh:dustinkirkland to fetch my keys from Github.

Here’s how!

First, edit your default LXD profile (or any other, for that matter):

$ lxc profile edit default

Then, add the config snippet, like this:

user.vendor-data: |
- name: root
ssh-import-id: gh:dustinkirkland
shell: /bin/bash
description: Default LXD profile
name: eth0
nictype: bridged
parent: lxdbr0
type: nic
name: default

Save and quit in your interactive editor, and then launch a new instance:

$ lxc launch ubuntu:x
Creating amazed-manatee
Starting amazed-manatee

Find your instance’s IP address:

$ lxc list
| amazed-manatee | RUNNING | (eth0) | fdce:be5e:b787:f7d2:216:3eff:fe1c:773 (eth0) | PERSISTENT | 0 |

And now SSH in!

$ ssh ubuntu@
$ ssh -6 ubuntu@fdce:be5e:b787:f7d2:216:3eff:fe1c:773



Ubuntu cloud

Ubuntu offers all the training, software infrastructure, tools, services and support you need for your public and private clouds.

Sign up for email updates

Choose the topics you're interested in


Related posts

LXD weekly status #39

Introduction The focus for this week was on CEPH and LXD clustering, trying to get the last few remaining pieces to work together properly. We’ve tagged a couple more betas as we went through that. We’ve also spent a good chunk of time…

LXD weekly status #38

Introduction This past week the LXD team was meeting in Budapest, Hungary. We spent most of our times working on a number of issues targeted at the final 3.0 releases. @freeekanayaka worked with @stgraber to track down an fix a testing…

MAAS for the home

This article originally appeared on Chris Sanders’ blog MAAS is designed to run in a data center where it expects to have control of DNS and DHCP. The use of an external DHCP server is listed as ‘may work but not supported’ in the…