Dustin Kirkland
on 25 February 2017

HOWTO: Automatically import your public SSH keys into LXD Instances


This article was last updated 8 year s ago.

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:

config:
user.vendor-data: |
#cloud-config
users:
- name: root
ssh-import-id: gh:dustinkirkland
shell: /bin/bash
description: Default LXD profile
devices:
eth0:
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
+----------------+---------+----------------------+----------------------------------------------+------------+-----------+
| NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS |
+----------------+---------+----------------------+----------------------------------------------+------------+-----------+
| amazed-manatee | RUNNING | 10.163.22.135 (eth0) | fdce:be5e:b787:f7d2:216:3eff:fe1c:773 (eth0) | PERSISTENT | 0 |
+----------------+---------+----------------------+----------------------------------------------+------------+-----------+

And now SSH in!

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

Enjoy!

:-Dustin


Newsletter
signup

Get the latest Ubuntu news and updates in your inbox.

By submitting this form, I confirm that I have read and agree to Canonical's Privacy Policy.

Related posts


Simon Fels
20 March 2024

Implementing an Android™ based cloud game streaming service with Anbox Cloud

Article Cloud and server

Since the outset, Anbox Cloud was developed with a variety of use cases for running Android at scale. Cloud gaming, more specifically for casual games as found on most user’s mobile devices, is the most prominent one and growing in popularity. Enterprises are challenged to find a solution that can keep up with the increasing

Simon Fels
20 March 2024


Miona Aleksic
18 January 2023

Containerization vs. Virtualization : understand the differences

Article Cloud and server

Containerization vs. Virtualization : understand the differences and benefits of each approach, as well as connections to cloud computing.

Miona Aleksic
18 January 2023


Canonical
25 June 2025

Native integration now available for Pure Storage and Canonical LXD

Article Canonical announcements

Canonical, the company behind Ubuntu, and Pure Storage, the IT pioneer delivering enterprise-grade all-flash storage, have partnered to introduce a native integration between LXD and Pure Storage FlashArray. This collaboration allows organizations to combine open source virtualization with industry-leading block storage...

Canonical
25 June 2025