Skip to content

Instantly share code, notes, and snippets.

@samsulmaarif
Forked from jeanlouisferey/LXD_SSH_KEY.md
Created June 30, 2018 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samsulmaarif/7db4e578459068aff0542aff571f1a09 to your computer and use it in GitHub Desktop.
Save samsulmaarif/7db4e578459068aff0542aff571f1a09 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