Skip to content

Instantly share code, notes, and snippets.

@mrhillsman
Forked from jeanlouisferey/LXD_SSH_KEY.md
Created March 16, 2018 17:43
Show Gist options
  • Save mrhillsman/0ab06649fe1c018012c1a68e4580d934 to your computer and use it in GitHub Desktop.
Save mrhillsman/0ab06649fe1c018012c1a68e4580d934 to your computer and use it in GitHub Desktop.
How to create a LXD Container with your ssh key in it (and with ssh server in the container)

How to create a LXD Container with your ssh key in it (and with ssh server in the container)

Create a brand new ed25519 key pair

ssh-keygen -o -a 100 -t ed25519

Get the pub key and put the result in your lxd default profile

cat ~/.ssh/ed25519.pub
lxc profile edit default
config:
user.user-data: |
  #cloud-config
  ssh_authorized_keys:
    - ssh-ed25519 AAAAC......

Create a new container from ubuntu

lxc launch Ubuntu.16.04 MyContainer

Get into the container and install ssh server

lxc exec MyContainer /bin/bash
apt update
apt upgrade
apt install ssh

Verify ssh connexion with key is ok

ssh root@Container -i .ssh/ed25519

Stop the Container and create a new image from this container

lxc stop MyContainer
lxc publish MyContainer --alias=MyImage description="My base image (with ssh and key)"
lxc delete MyContainer

Start a new container and verify everything is ok

lxc launch MyImage TestContainer
lxc list (to get TestContainer Ip)
sh root@TestContainer -i .ssh/ed25519
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment