Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
@thepenguinthatwants

This comment has been minimized.

Copy link

@thepenguinthatwants thepenguinthatwants commented Dec 22, 2019

Hi!

I've tried your steps but I only get

Permission denied (publickey)

When I try to ssh to the image. Is there some steps undocumented or something?

@thepenguinthatwants

This comment has been minimized.

Copy link

@thepenguinthatwants thepenguinthatwants commented Dec 24, 2019

no-port-forwarding,no-agent-forwarding,no-X11-forwarding,command="echo 'Please login as the user "ubuntu" rather than the user "root".';echo;sleep 10"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment