LXD adding Authorised Keys to ubuntu-cloud-image Containers

If you are using an Ubuntu cloud image (such as what "lxd launch ubuntu:" would get you), then you can set the "user.user-data" configuration key and set it to valid cloud-init metadata.

The following contend are copy from : lxd issues 1289 -- Question: Adding Authorised Keys to Containers

stgraber@dakara:~$ lxc init ubuntu my-container  
Creating my-container done.  
stgraber@dakara:~$ cat .ssh/id_rsa.pub  
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCUxZlF5ppeH4Al6FLRBP0yXuNp8FJETdbQ68C7NRp1KkFAkOV92pf0pX+Qne0INKKGXTYqvkmvnF3Y1Hymg66nBnaPjS5xoq6GZH3nACQ9BvkPo+sMdzFjWgGC0FvPau+HdOwf4+obOTcRFW6vuqFoEnz9kNN2wTe0Hc1hPGWihq0dxzgkwaBH+EVVYwKURVsDz5VqN7weL6FI7RA2l3OZyH0WHebzDay4bweBANQ1BHr1iVsJkz8kCA77M29Mb8t9nBulwVbfjAYssqLEjdTQCLn2xgfXMVtI/w0j9YDKe4ondXeFHLwfEuPI83lO7YzgKarJeibKkLGVjeLvYIq/ stgraber@dakara  
stgraber@dakara:~$ (  
> cat << EOF
> #cloud-config
> ssh_authorized_keys:
>  - ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCUxZlF5ppeH4Al6FLRBP0yXuNp8FJETdbQ68C7NRp1KkFAkOV92pf0pX+Qne0INKKGXTYqvkmvnF3Y1Hymg66nBnaPjS5xoq6GZH3nACQ9BvkPo+sMdzFjWgGC0FvPau+HdOwf4+obOTcRFW6vuqFoEnz9kNN2wTe0Hc1hPGWihq0dxzgkwaBH+EVVYwKURVsDz5VqN7weL6FI7RA2l3OZyH0WHebzDay4bweBANQ1BHr1iVsJkz8kCA77M29Mb8t9nBulwVbfjAYssqLEjdTQCLn2xgfXMVtI/w0j9YDKe4ondXeFHLwfEuPI83lO7YzgKarJeibKkLGVjeLvYIq/ stgraber@dakara
> EOF
> ) | lxc config set my-container user.user-data -
stgraber@dakara:~$ lxc start my-container  
stgraber@dakara:~$ lxc info my-container  
Name: my-container  
Status: Running  
Init: 1343939  
Ips:  
  eth0: IPV4    10.0.3.24
  eth0: IPV6    2607:f2c0:f00f:2760:216:3eff:feb5:514a
  lo:   IPV4    127.0.0.1
  lo:   IPV6    ::1
stgraber@dakara:~$ ssh ubuntu@10.0.3.24  
The authenticity of host '10.0.3.24 (10.0.3.24)' can't be established.  
ECDSA key fingerprint is 34:f9:49:81:60:9b:20:55:c1:f1:11:97:cb:32:70:d4.  
No matching host key fingerprint found in DNS.  
Are you sure you want to continue connecting (yes/no)? yes  
Warning: Permanently added '10.0.3.24' (ECDSA) to the list of known hosts.  
Welcome to Ubuntu 14.04.3 LTS (GNU/Linux 3.13.0-66-generic x86_64)

 * Documentation:  https://help.ubuntu.com/

  System information as of Sat Nov  7 17:20:26 UTC 2015

  System load:    1.05      Memory usage: 0%   Processes:       14
  Usage of /home: unknown   Swap usage:   0%   Users logged in: 0

  Graph this data and manage this system at:
    https://landscape.canonical.com/

  Get cloud support with Ubuntu Advantage Cloud Guest:
    http://www.ubuntu.com/business/services/cloud

0 packages can be updated.  
0 updates are security updates.



The programs included with the Ubuntu system are free software;  
the exact distribution terms for each program are described in the  
individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by  
applicable law.

ubuntu@my-container:~$  

You can also set user.user-data in your "default" profile instead so that it applies to all containers.

A very clear explanation.