Your IP : 216.73.217.13


Current Path : /snap/lxd/38450/share/lxd-documentation/cloud-init/
Upload File :
Current File : //snap/lxd/38450/share/lxd-documentation/cloud-init/index.html

<!doctype html>
<html class="no-js" lang="en" data-content_root="../">
  <head><meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <meta name="color-scheme" content="light dark"><meta name="viewport" content="width=device-width, initial-scale=1" />
<meta property="og:title" content="How to use cloud-init" />
<meta property="og:type" content="website" />
<meta property="og:url" content="/cloud-init/" />
<meta property="og:site_name" content="LXD documentation" />
<meta property="og:description" content="cloud-init is a tool for automatically initializing and customizing an instance of a Linux distribution. By adding cloud-init configuration to your instance, you can instruct cloud-init to execute ..." />
<meta property="og:image" content="https://documentation.ubuntu.com/lxd/latest/_static/lxd_tag.png" />
<meta property="og:image:alt" content="LXD documentation" />
<meta name="description" content="cloud-init is a tool for automatically initializing and customizing an instance of a Linux distribution. By adding cloud-init configuration to your instance, you can instruct cloud-init to execute ..." />

    <meta property="article:modified_time" content="2026-02-12T14:01:41+00:00" /><link rel="index" title="Index" href="../genindex/"><link rel="search" title="Search" href="../search/"><link rel="next" title="How to add a routed NIC device to a virtual machine" href="../howto/instances_routed_nic_vm/"><link rel="prev" title="How to run commands in an instance" href="../instance-exec/">
        <link rel="canonical" href="/cloud-init/">

    <link rel="shortcut icon" href="../_static/favicon.ico"><!-- Generated with Sphinx 7.4.7 and Furo 2025.12.19 -->
        <title>How to use cloud-init - LXD documentation</title>
      <link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=d111a655" />
    <link rel="stylesheet" type="text/css" href="../_static/styles/furo.css?v=7bdb33bb" />
    <link rel="stylesheet" type="text/css" href="../_static/copybutton.css?v=76b2166b" />
    <link rel="stylesheet" type="text/css" href="../_static/config-options.css" />
    <link rel="stylesheet" type="text/css" href="../_static/related-links.css" />
    <link rel="stylesheet" type="text/css" href="../_static/terminal.css" />
    <link rel="stylesheet" type="text/css" href="../_static/youtube.css" />
    <link rel="stylesheet" type="text/css" href="../_static/sphinx-design.min.css?v=95c83b7e" />
    <link rel="stylesheet" type="text/css" href="../_static/tabs.css?v=a5c4661c" />
    <link rel="stylesheet" type="text/css" href="../_static/styles/furo-extensions.css?v=8dab3a3b" />
    <link rel="stylesheet" type="text/css" href="../_static/lxd_custom.css?v=bfbf4da2" />
    <link rel="stylesheet" type="text/css" href="../_static/cookie-banner.css?v=b74831ab" />
    <link rel="stylesheet" type="text/css" href="../_static/custom.css?v=e189117a" />
    <link rel="stylesheet" type="text/css" href="../_static/header.css?v=a8078839" />
    <link rel="stylesheet" type="text/css" href="../_static/github_issue_links.css?v=3d761185" />
    <link rel="stylesheet" type="text/css" href="../_static/furo_colors.css?v=825fec6f" />
    
</head>
  <body>
    <header id="header" class="p-navigation">
  <!-- Google Tag Manager -->
  <script>
    (function(w, d, s, l, i) {
      w[l] = w[l] || [];
      w[l].push({
        'gtm.start': new Date().getTime(),
        event: 'gtm.js'
      });
      var f = d.getElementsByTagName(s)[0];
      var j = d.createElement(s);
      var dl = '';
      if (l != 'dataLayer') {
          dl = '&l=' + l;
      }
      j.async = true;
      j.src = 'https://www.googletagmanager.com/gtm.js?id=' + i + dl;
      f.parentNode.insertBefore(j, f);
    })(window, document, 'script', 'dataLayer', 'GTM-KNX3CJC');
  </script>
  
  <div class="p-navigation__nav" role="menubar">

    <ul class="p-navigation__links" role="menu">

      <li>
        
        <a class="p-logo" href="https://canonical.com/lxd" aria-current="page">
          <img src="../_static/lxd_tag.png" alt="Logo" class="p-logo-image">
          <div class="p-logo-text p-heading--4">LXD
          </div>
        </a>
        
      </li>

      <li class="nav-ubuntu-com">
        
        <a href="https://canonical.com/lxd" class="p-navigation__link">canonical.com/lxd</a>
        
      </li>

      <li class="nav-dropdown">
        <a href="#" class="p-navigation__link nav-more-links"
           id="more-resources-toggle"
           aria-haspopup="true"
           aria-expanded="false">
          More resources
        </a>
        <ul class="more-links-dropdown" aria-labelledby="more-resources-toggle">
          
          <li>
            <a href="https://discourse.ubuntu.com/c/lxd/" class="p-navigation__sub-link p-dropdown__link">Discourse</a>
          </li>
          
      
          
      
          
          <li>
            <a href="https://matrix.to/#/#documentation:ubuntu.com" class="p-navigation__sub-link p-dropdown__link">Matrix</a>
          </li>
          
      
          
          <li>
            <a href="https://github.com/canonical/lxd" class="p-navigation__sub-link p-dropdown__link">GitHub</a>
          </li>
          

        </ul>
      </li>

    </ul>
  </div>
</header>
   
    <script>
      document.body.dataset.theme = localStorage.getItem("theme") || "auto";
    </script>
    

<svg xmlns="http://www.w3.org/2000/svg" style="display: none;">
  <symbol id="svg-toc" viewBox="0 0 24 24">
    <title>Contents</title>
    <svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 1024 1024">
      <path d="M408 442h480c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8H408c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8zm-8 204c0 4.4 3.6 8 8 8h480c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8H408c-4.4 0-8 3.6-8 8v56zm504-486H120c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h784c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zm0 632H120c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h784c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zM115.4 518.9L271.7 642c5.8 4.6 14.4.5 14.4-6.9V388.9c0-7.4-8.5-11.5-14.4-6.9L115.4 505.1a8.74 8.74 0 0 0 0 13.8z"/>
    </svg>
  </symbol>
  <symbol id="svg-menu" viewBox="0 0 24 24">
    <title>Menu</title>
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
      stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather-menu">
      <line x1="3" y1="12" x2="21" y2="12"></line>
      <line x1="3" y1="6" x2="21" y2="6"></line>
      <line x1="3" y1="18" x2="21" y2="18"></line>
    </svg>
  </symbol>
  <symbol id="svg-arrow-right" viewBox="0 0 24 24">
    <title>Expand</title>
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
      stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather-chevron-right">
      <polyline points="9 18 15 12 9 6"></polyline>
    </svg>
  </symbol>
  <symbol id="svg-sun" viewBox="0 0 24 24">
    <title>Light mode</title>
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
      stroke-width="1" stroke-linecap="round" stroke-linejoin="round" class="feather-sun">
      <circle cx="12" cy="12" r="5"></circle>
      <line x1="12" y1="1" x2="12" y2="3"></line>
      <line x1="12" y1="21" x2="12" y2="23"></line>
      <line x1="4.22" y1="4.22" x2="5.64" y2="5.64"></line>
      <line x1="18.36" y1="18.36" x2="19.78" y2="19.78"></line>
      <line x1="1" y1="12" x2="3" y2="12"></line>
      <line x1="21" y1="12" x2="23" y2="12"></line>
      <line x1="4.22" y1="19.78" x2="5.64" y2="18.36"></line>
      <line x1="18.36" y1="5.64" x2="19.78" y2="4.22"></line>
    </svg>
  </symbol>
  <symbol id="svg-moon" viewBox="0 0 24 24">
    <title>Dark mode</title>
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
      stroke-width="1" stroke-linecap="round" stroke-linejoin="round" class="icon-tabler-moon">
      <path stroke="none" d="M0 0h24v24H0z" fill="none" />
      <path d="M12 3c.132 0 .263 0 .393 0a7.5 7.5 0 0 0 7.92 12.446a9 9 0 1 1 -8.313 -12.454z" />
    </svg>
  </symbol>
  <symbol id="svg-sun-with-moon" viewBox="0 0 24 24">
    <title>Auto light/dark, in light mode</title>
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
      stroke-width="1" stroke-linecap="round" stroke-linejoin="round"
      class="icon-custom-derived-from-feather-sun-and-tabler-moon">
      <path style="opacity: 50%" d="M 5.411 14.504 C 5.471 14.504 5.532 14.504 5.591 14.504 C 3.639 16.319 4.383 19.569 6.931 20.352 C 7.693 20.586 8.512 20.551 9.25 20.252 C 8.023 23.207 4.056 23.725 2.11 21.184 C 0.166 18.642 1.702 14.949 4.874 14.536 C 5.051 14.512 5.231 14.5 5.411 14.5 L 5.411 14.504 Z"/>
      <line x1="14.5" y1="3.25" x2="14.5" y2="1.25"/>
      <line x1="14.5" y1="15.85" x2="14.5" y2="17.85"/>
      <line x1="10.044" y1="5.094" x2="8.63" y2="3.68"/>
      <line x1="19" y1="14.05" x2="20.414" y2="15.464"/>
      <line x1="8.2" y1="9.55" x2="6.2" y2="9.55"/>
      <line x1="20.8" y1="9.55" x2="22.8" y2="9.55"/>
      <line x1="10.044" y1="14.006" x2="8.63" y2="15.42"/>
      <line x1="19" y1="5.05" x2="20.414" y2="3.636"/>
      <circle cx="14.5" cy="9.55" r="3.6"/>
    </svg>
  </symbol>
  <symbol id="svg-moon-with-sun" viewBox="0 0 24 24">
    <title>Auto light/dark, in dark mode</title>
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
      stroke-width="1" stroke-linecap="round" stroke-linejoin="round"
      class="icon-custom-derived-from-feather-sun-and-tabler-moon">
      <path d="M 8.282 7.007 C 8.385 7.007 8.494 7.007 8.595 7.007 C 5.18 10.184 6.481 15.869 10.942 17.24 C 12.275 17.648 13.706 17.589 15 17.066 C 12.851 22.236 5.91 23.143 2.505 18.696 C -0.897 14.249 1.791 7.786 7.342 7.063 C 7.652 7.021 7.965 7 8.282 7 L 8.282 7.007 Z"/>
      <line style="opacity: 50%" x1="18" y1="3.705" x2="18" y2="2.5"/>
      <line style="opacity: 50%" x1="18" y1="11.295" x2="18" y2="12.5"/>
      <line style="opacity: 50%" x1="15.316" y1="4.816" x2="14.464" y2="3.964"/>
      <line style="opacity: 50%" x1="20.711" y1="10.212" x2="21.563" y2="11.063"/>
      <line style="opacity: 50%" x1="14.205" y1="7.5" x2="13.001" y2="7.5"/>
      <line style="opacity: 50%" x1="21.795" y1="7.5" x2="23" y2="7.5"/>
      <line style="opacity: 50%" x1="15.316" y1="10.184" x2="14.464" y2="11.036"/>
      <line style="opacity: 50%" x1="20.711" y1="4.789" x2="21.563" y2="3.937"/>
      <circle style="opacity: 50%" cx="18" cy="7.5" r="2.169"/>
    </svg>
  </symbol>
  <symbol id="svg-pencil" viewBox="0 0 24 24">
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
      stroke-width="1" stroke-linecap="round" stroke-linejoin="round" class="icon-tabler-pencil-code">
      <path d="M4 20h4l10.5 -10.5a2.828 2.828 0 1 0 -4 -4l-10.5 10.5v4" />
      <path d="M13.5 6.5l4 4" />
      <path d="M20 21l2 -2l-2 -2" />
      <path d="M17 17l-2 2l2 2" />
    </svg>
  </symbol>
  <symbol id="svg-eye" viewBox="0 0 24 24">
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
      stroke-width="1" stroke-linecap="round" stroke-linejoin="round" class="icon-tabler-eye-code">
      <path stroke="none" d="M0 0h24v24H0z" fill="none" />
      <path d="M10 12a2 2 0 1 0 4 0a2 2 0 0 0 -4 0" />
      <path
        d="M11.11 17.958c-3.209 -.307 -5.91 -2.293 -8.11 -5.958c2.4 -4 5.4 -6 9 -6c3.6 0 6.6 2 9 6c-.21 .352 -.427 .688 -.647 1.008" />
      <path d="M20 21l2 -2l-2 -2" />
      <path d="M17 17l-2 2l2 2" />
    </svg>
  </symbol>
</svg>

<input type="checkbox" class="sidebar-toggle" name="__navigation" id="__navigation" aria-label="Toggle site navigation sidebar">
<input type="checkbox" class="sidebar-toggle" name="__toc" id="__toc" aria-label="Toggle table of contents sidebar">
<label class="overlay sidebar-overlay" for="__navigation"></label>
<label class="overlay toc-overlay" for="__toc"></label>

<a class="skip-to-content muted-link" href="#furo-main-content">Skip to content</a>



<div class="page">
  <header class="mobile-header">
    <div class="header-left">
      <label class="nav-overlay-icon" for="__navigation">
        <span class="icon"><svg><use href="#svg-menu"></use></svg></span>
      </label>
    </div>
    <div class="header-center">
      <a href="../"><div class="brand">LXD documentation</div></a>
    </div>
    <div class="header-right">
      <div class="theme-toggle-container theme-toggle-header">
        <button class="theme-toggle" aria-label="Toggle Light / Dark / Auto color theme">
          <svg class="theme-icon-when-auto-light"><use href="#svg-sun-with-moon"></use></svg>
          <svg class="theme-icon-when-auto-dark"><use href="#svg-moon-with-sun"></use></svg>
          <svg class="theme-icon-when-dark"><use href="#svg-moon"></use></svg>
          <svg class="theme-icon-when-light"><use href="#svg-sun"></use></svg>
        </button>
      </div>
      <label class="toc-overlay-icon toc-header-icon" for="__toc">
        <span class="icon"><svg><use href="#svg-toc"></use></svg></span>
      </label>
    </div>
  </header>
  <aside class="sidebar-drawer">
    <div class="sidebar-container">
      
      <div class="sidebar-sticky"><a class="sidebar-brand" href="../">
  
  <span class="sidebar-brand-text">LXD documentation</span>
  
</a><form class="sidebar-search-container" method="get" action="../search/" role="search">
    <input class="sidebar-search" placeholder="Search" name="q" aria-label="Search">
    <input type="submit" value="Go">
    <input type="hidden" name="check_keywords" value="yes">
    <input type="hidden" name="area" value="default">
  </form>
  <div id="searchbox"></div><div class="sidebar-scroll"><div class="sidebar-tree">
  <ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../">LXD</a></li>
<li class="toctree-l1"><a class="reference internal" href="../tutorial/first_steps/">Tutorial</a></li>
<li class="toctree-l1 current has-children"><a class="reference internal" href="../howto/">How-to guides</a><input aria-label="Toggle navigation of How-to guides" checked="" class="toctree-checkbox" id="toctree-checkbox-1" name="toctree-checkbox-1" role="switch" type="checkbox"/><label for="toctree-checkbox-1"><span class="icon"><svg><use href="#svg-arrow-right"></use></svg></span></label><ul class="current">
<li class="toctree-l2 has-children"><a class="reference internal" href="../getting_started/">Getting started</a><input aria-label="Toggle navigation of Getting started" class="toctree-checkbox" id="toctree-checkbox-2" name="toctree-checkbox-2" role="switch" type="checkbox"/><label for="toctree-checkbox-2"><span class="icon"><svg><use href="#svg-arrow-right"></use></svg></span></label><ul>
<li class="toctree-l3"><a class="reference internal" href="../installing/">Install LXD</a></li>
<li class="toctree-l3"><a class="reference internal" href="../howto/initialize/">Initialize LXD</a></li>
<li class="toctree-l3"><a class="reference internal" href="../howto/access_ui/">Access the UI</a></li>
<li class="toctree-l3"><a class="reference internal" href="../howto/access_documentation/">Access documentation locally</a></li>
</ul>
</li>
<li class="toctree-l2 has-children"><a class="reference internal" href="../operation/">LXD server and client</a><input aria-label="Toggle navigation of LXD server and client" class="toctree-checkbox" id="toctree-checkbox-3" name="toctree-checkbox-3" role="switch" type="checkbox"/><label for="toctree-checkbox-3"><span class="icon"><svg><use href="#svg-arrow-right"></use></svg></span></label><ul>
<li class="toctree-l3"><a class="reference internal" href="../howto/server_expose/">Expose LXD to the network</a></li>
<li class="toctree-l3"><a class="reference internal" href="../howto/server_configure/">Configure the LXD server</a></li>
<li class="toctree-l3 has-children"><a class="reference internal" href="../howto/oidc/">Configure single sign-on with OIDC</a><input aria-label="Toggle navigation of Configure single sign-on with OIDC" class="toctree-checkbox" id="toctree-checkbox-4" name="toctree-checkbox-4" role="switch" type="checkbox"/><label for="toctree-checkbox-4"><span class="icon"><svg><use href="#svg-arrow-right"></use></svg></span></label><ul>
<li class="toctree-l4"><a class="reference internal" href="../howto/oidc_auth0/">How to configure Auth0</a></li>
<li class="toctree-l4"><a class="reference internal" href="../howto/oidc_ory/">How to configure Ory Hydra</a></li>
<li class="toctree-l4"><a class="reference internal" href="../howto/oidc_keycloak/">How to configure Keycloak</a></li>
<li class="toctree-l4"><a class="reference internal" href="../howto/oidc_entra_id/">How to configure Entra ID</a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="../remotes/">Add remote servers</a></li>
<li class="toctree-l3"><a class="reference internal" href="../howto/lxc_alias/">Add command aliases</a></li>
</ul>
</li>
<li class="toctree-l2 current has-children"><a class="reference internal" href="../instances/">Instances</a><input aria-label="Toggle navigation of Instances" checked="" class="toctree-checkbox" id="toctree-checkbox-5" name="toctree-checkbox-5" role="switch" type="checkbox"/><label for="toctree-checkbox-5"><span class="icon"><svg><use href="#svg-arrow-right"></use></svg></span></label><ul class="current">
<li class="toctree-l3"><a class="reference internal" href="../howto/instances_create/">Create instances</a></li>
<li class="toctree-l3"><a class="reference internal" href="../howto/instances_configure/">Configure instances</a></li>
<li class="toctree-l3"><a class="reference internal" href="../howto/instances_manage/">Manage instances</a></li>
<li class="toctree-l3"><a class="reference internal" href="../profiles/">Use profiles</a></li>
<li class="toctree-l3"><a class="reference internal" href="../howto/instances_troubleshoot/">Troubleshoot errors</a></li>
<li class="toctree-l3"><a class="reference internal" href="../howto/instances_ubuntu_pro_attach/">Auto attach Ubuntu Pro</a></li>
<li class="toctree-l3"><a class="reference internal" href="../howto/instances_access_files/">Access files</a></li>
<li class="toctree-l3"><a class="reference internal" href="../howto/instances_console/">Access the console</a></li>
<li class="toctree-l3"><a class="reference internal" href="../instance-exec/">Run commands</a></li>
<li class="toctree-l3 current current-page"><a class="current reference internal" href="#">Use cloud-init</a></li>
<li class="toctree-l3"><a class="reference internal" href="../howto/instances_routed_nic_vm/">Add a routed NIC to a VM</a></li>
<li class="toctree-l3"><a class="reference internal" href="../howto/instances_backup/">Back up instances</a></li>
<li class="toctree-l3"><a class="reference internal" href="../howto/instances_migrate/">Migrate instances</a></li>
<li class="toctree-l3"><a class="reference internal" href="../howto/import_machines_to_instances/">Import existing machines</a></li>
<li class="toctree-l3"><a class="reference internal" href="../howto/container_gpu_passthrough_with_docker/">Pass NVIDIA GPUs</a></li>
</ul>
</li>
<li class="toctree-l2 has-children"><a class="reference internal" href="../images/">Images</a><input aria-label="Toggle navigation of Images" class="toctree-checkbox" id="toctree-checkbox-6" name="toctree-checkbox-6" role="switch" type="checkbox"/><label for="toctree-checkbox-6"><span class="icon"><svg><use href="#svg-arrow-right"></use></svg></span></label><ul>
<li class="toctree-l3"><a class="reference internal" href="../howto/images_remote/">Use remote images</a></li>
<li class="toctree-l3"><a class="reference internal" href="../howto/images_manage/">Manage images</a></li>
<li class="toctree-l3"><a class="reference internal" href="../howto/images_profiles/">Associate profiles</a></li>
<li class="toctree-l3"><a class="reference internal" href="../howto/images_copy/">Copy and import images</a></li>
<li class="toctree-l3"><a class="reference internal" href="../howto/images_create/">Create images</a></li>
</ul>
</li>
<li class="toctree-l2 has-children"><a class="reference internal" href="../projects/">Projects</a><input aria-label="Toggle navigation of Projects" class="toctree-checkbox" id="toctree-checkbox-7" name="toctree-checkbox-7" role="switch" type="checkbox"/><label for="toctree-checkbox-7"><span class="icon"><svg><use href="#svg-arrow-right"></use></svg></span></label><ul>
<li class="toctree-l3"><a class="reference internal" href="../howto/projects_create/">Create and configure</a></li>
<li class="toctree-l3"><a class="reference internal" href="../howto/projects_work/">Work with projects</a></li>
<li class="toctree-l3"><a class="reference internal" href="../howto/projects_confine/">Confine users to projects</a></li>
</ul>
</li>
<li class="toctree-l2 has-children"><a class="reference internal" href="../storage/">Storage</a><input aria-label="Toggle navigation of Storage" class="toctree-checkbox" id="toctree-checkbox-8" name="toctree-checkbox-8" role="switch" type="checkbox"/><label for="toctree-checkbox-8"><span class="icon"><svg><use href="#svg-arrow-right"></use></svg></span></label><ul>
<li class="toctree-l3"><a class="reference internal" href="../howto/storage_pools/">Manage pools</a></li>
<li class="toctree-l3"><a class="reference internal" href="../howto/storage_volumes/">Manage volumes</a></li>
<li class="toctree-l3"><a class="reference internal" href="../howto/storage_buckets/">Manage buckets</a></li>
<li class="toctree-l3"><a class="reference internal" href="../howto/storage_create_instance/">Create an instance in a pool</a></li>
<li class="toctree-l3"><a class="reference internal" href="../howto/storage_backup_volume/">Back up a volume</a></li>
<li class="toctree-l3"><a class="reference internal" href="../howto/storage_move_volume/">Move or copy a volume</a></li>
<li class="toctree-l3"><a class="reference internal" href="../howto/storage_csi/">Use the LXD CSI driver with Kubernetes</a></li>
</ul>
</li>
<li class="toctree-l2 has-children"><a class="reference internal" href="../networks/">Networking</a><input aria-label="Toggle navigation of Networking" class="toctree-checkbox" id="toctree-checkbox-9" name="toctree-checkbox-9" role="switch" type="checkbox"/><label for="toctree-checkbox-9"><span class="icon"><svg><use href="#svg-arrow-right"></use></svg></span></label><ul>
<li class="toctree-l3"><a class="reference internal" href="../howto/network_create/">Create a network</a></li>
<li class="toctree-l3"><a class="reference internal" href="../howto/network_configure/">Configure a network</a></li>
<li class="toctree-l3"><a class="reference internal" href="../howto/network_bgp/">Configure as BGP server</a></li>
<li class="toctree-l3"><a class="reference internal" href="../howto/network_acls/">Configure network ACLs</a></li>
<li class="toctree-l3"><a class="reference internal" href="../howto/network_forwards/">Configure forwards</a></li>
<li class="toctree-l3"><a class="reference internal" href="../howto/network_zones/">Configure network zones</a></li>
<li class="toctree-l3"><a class="reference internal" href="../howto/network_bridge_firewalld/">Configure your firewall</a></li>
<li class="toctree-l3"><a class="reference internal" href="../howto/network_bridge_resolved/">Integrate with resolved</a></li>
<li class="toctree-l3"><a class="reference internal" href="../howto/network_ovn_setup/">Set up OVN</a></li>
<li class="toctree-l3"><a class="reference internal" href="../howto/network_load_balancers/">Configure load balancers</a></li>
<li class="toctree-l3"><a class="reference internal" href="../howto/network_ovn_peers/">Configure peer routing</a></li>
<li class="toctree-l3"><a class="reference internal" href="../howto/network_ipam/">Display IPAM information</a></li>
</ul>
</li>
<li class="toctree-l2 has-children"><a class="reference internal" href="../clustering/">Clustering</a><input aria-label="Toggle navigation of Clustering" class="toctree-checkbox" id="toctree-checkbox-10" name="toctree-checkbox-10" role="switch" type="checkbox"/><label for="toctree-checkbox-10"><span class="icon"><svg><use href="#svg-arrow-right"></use></svg></span></label><ul>
<li class="toctree-l3"><a class="reference internal" href="../howto/cluster_form/">Form a cluster</a></li>
<li class="toctree-l3"><a class="reference internal" href="../howto/cluster_manage/">Manage a cluster</a></li>
<li class="toctree-l3"><a class="reference internal" href="../howto/cluster_config_networks/">Configure networks</a></li>
<li class="toctree-l3"><a class="reference internal" href="../howto/cluster_config_storage/">Configure storage</a></li>
<li class="toctree-l3"><a class="reference internal" href="../howto/cluster_manage_instance/">Manage instances</a></li>
<li class="toctree-l3"><a class="reference internal" href="../howto/cluster_groups/">Set up cluster groups</a></li>
<li class="toctree-l3"><a class="reference internal" href="../howto/cluster_placement_groups/">Use placement groups</a></li>
<li class="toctree-l3"><a class="reference internal" href="../howto/cluster_recover/">Recover a cluster</a></li>
<li class="toctree-l3"><a class="reference internal" href="../howto/cluster_vip/">Set up a highly available virtual IP</a></li>
</ul>
</li>
<li class="toctree-l2 has-children"><a class="reference internal" href="../production-setup/">Production setup</a><input aria-label="Toggle navigation of Production setup" class="toctree-checkbox" id="toctree-checkbox-11" name="toctree-checkbox-11" role="switch" type="checkbox"/><label for="toctree-checkbox-11"><span class="icon"><svg><use href="#svg-arrow-right"></use></svg></span></label><ul>
<li class="toctree-l3"><a class="reference internal" href="../howto/benchmark_performance/">Benchmark performance</a></li>
<li class="toctree-l3"><a class="reference internal" href="../howto/network_increase_bandwidth/">Increase bandwidth</a></li>
<li class="toctree-l3"><a class="reference internal" href="../metrics/">Monitor metrics</a></li>
<li class="toctree-l3"><a class="reference internal" href="../howto/logs_loki/">Send logs to Loki</a></li>
<li class="toctree-l3"><a class="reference internal" href="../howto/grafana/">Set up Grafana</a></li>
<li class="toctree-l3"><a class="reference internal" href="../backup/">Back up a server</a></li>
<li class="toctree-l3"><a class="reference internal" href="../howto/disaster_recovery/">Recover instances</a></li>
<li class="toctree-l3"><a class="reference internal" href="../howto/disaster_recovery_replication/">Disaster recovery with storage replication</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../howto/snap/">Manage the snap</a></li>
<li class="toctree-l2"><a class="reference internal" href="../howto/security_harden/">Harden security</a></li>
<li class="toctree-l2 has-children"><a class="reference internal" href="../howto/troubleshoot/">Troubleshooting</a><input aria-label="Toggle navigation of Troubleshooting" class="toctree-checkbox" id="toctree-checkbox-12" name="toctree-checkbox-12" role="switch" type="checkbox"/><label for="toctree-checkbox-12"><span class="icon"><svg><use href="#svg-arrow-right"></use></svg></span></label><ul>
<li class="toctree-l3"><a class="reference internal" href="../howto/network_bridge_firewalld/">Configure your firewall</a></li>
<li class="toctree-l3"><a class="reference internal" href="../howto/instances_troubleshoot/">Troubleshoot instances</a></li>
<li class="toctree-l3"><a class="reference internal" href="../howto/dqlite_troubleshoot/">Troubleshoot Dqlite</a></li>
<li class="toctree-l3"><a class="reference internal" href="../debugging/">Debug LXD</a></li>
<li class="toctree-l3"><a class="reference internal" href="../faq/">Frequently asked</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../support/">Get support</a></li>
<li class="toctree-l2"><a class="reference internal" href="../contributing/">Contribute to LXD</a></li>
<li class="toctree-l2"><a class="reference internal" href="../howto/auth_bearer/">How to authenticate to the LXD API using bearer tokens</a></li>
<li class="toctree-l2"><a class="reference internal" href="../howto/devlxd_authenticate/">How to authenticate to the DevLXD API</a></li>
</ul>
</li>
<li class="toctree-l1 has-children"><a class="reference internal" href="../explanation/">Explanation</a><input aria-label="Toggle navigation of Explanation" class="toctree-checkbox" id="toctree-checkbox-13" name="toctree-checkbox-13" role="switch" type="checkbox"/><label for="toctree-checkbox-13"><span class="icon"><svg><use href="#svg-arrow-right"></use></svg></span></label><ul>
<li class="toctree-l2"><a class="reference internal" href="../explanation/lxd_lxc/"><code class="docutils literal notranslate"><span class="pre">lxd</span></code> and <code class="docutils literal notranslate"><span class="pre">lxc</span></code></a></li>
<li class="toctree-l2"><a class="reference internal" href="../explanation/instances/">Containers and VMs</a></li>
<li class="toctree-l2"><a class="reference internal" href="../image-handling/">Local and remote images</a></li>
<li class="toctree-l2"><a class="reference internal" href="../explanation/storage/">Storage pools, volumes, and buckets</a></li>
<li class="toctree-l2"><a class="reference internal" href="../explanation/networks/">Networking setups</a></li>
<li class="toctree-l2"><a class="reference internal" href="../database/">The LXD Dqlite database</a></li>
<li class="toctree-l2"><a class="reference internal" href="../explanation/lxc_show_info/"><code class="docutils literal notranslate"><span class="pre">lxc</span></code> <code class="docutils literal notranslate"><span class="pre">show</span></code> and <code class="docutils literal notranslate"><span class="pre">info</span></code></a></li>
<li class="toctree-l2"><a class="reference internal" href="../authentication/">Remote API authentication</a></li>
<li class="toctree-l2"><a class="reference internal" href="../explanation/authorization/">Remote API authorization</a></li>
<li class="toctree-l2"><a class="reference internal" href="../explanation/projects/">Instances grouping with projects</a></li>
<li class="toctree-l2"><a class="reference internal" href="../explanation/clusters/">Clusters</a></li>
<li class="toctree-l2"><a class="reference internal" href="../explanation/performance_tuning/">Performance tuning</a></li>
<li class="toctree-l2"><a class="reference internal" href="../explanation/security/">Security</a></li>
<li class="toctree-l2"><a class="reference internal" href="../explanation/bpf/">Privilege delegation using BPF Token</a></li>
<li class="toctree-l2"><a class="reference internal" href="../explanation/csi/">The LXD CSI driver</a></li>
</ul>
</li>
<li class="toctree-l1 has-children"><a class="reference internal" href="../reference/">Reference</a><input aria-label="Toggle navigation of Reference" class="toctree-checkbox" id="toctree-checkbox-14" name="toctree-checkbox-14" role="switch" type="checkbox"/><label for="toctree-checkbox-14"><span class="icon"><svg><use href="#svg-arrow-right"></use></svg></span></label><ul>
<li class="toctree-l2"><a class="reference internal" href="../requirements/">Requirements</a></li>
<li class="toctree-l2"><a class="reference internal" href="../architectures/">Architectures</a></li>
<li class="toctree-l2 has-children"><a class="reference internal" href="../reference/release-notes/">Release notes</a><input aria-label="Toggle navigation of Release notes" class="toctree-checkbox" id="toctree-checkbox-15" name="toctree-checkbox-15" role="switch" type="checkbox"/><label for="toctree-checkbox-15"><span class="icon"><svg><use href="#svg-arrow-right"></use></svg></span></label><ul>
<li class="toctree-l3"><a class="reference internal" href="../reference/release-notes/release-notes-6.7/">LXD 6.7</a></li>
<li class="toctree-l3"><a class="reference internal" href="../reference/release-notes/release-notes-6.6/">LXD 6.6</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../reference/releases-snap/">Releases and snap</a></li>
<li class="toctree-l2"><a class="reference internal" href="../reference/remote_image_servers/">Remote image servers</a></li>
<li class="toctree-l2"><a class="reference internal" href="../reference/image_format/">Image format</a></li>
<li class="toctree-l2"><a class="reference internal" href="../guest-os-compatibility/">Guest OS compatibility</a></li>
<li class="toctree-l2"><a class="reference internal" href="../container-environment/">Container environment</a></li>
<li class="toctree-l2"><a class="reference internal" href="../config-options/">Configuration option index</a></li>
<li class="toctree-l2"><a class="reference internal" href="../server/">Server configuration</a></li>
<li class="toctree-l2 has-children"><a class="reference internal" href="../explanation/instance_config/">Instance configuration</a><input aria-label="Toggle navigation of Instance configuration" class="toctree-checkbox" id="toctree-checkbox-16" name="toctree-checkbox-16" role="switch" type="checkbox"/><label for="toctree-checkbox-16"><span class="icon"><svg><use href="#svg-arrow-right"></use></svg></span></label><ul>
<li class="toctree-l3"><a class="reference internal" href="../reference/instance_properties/">Instance properties</a></li>
<li class="toctree-l3"><a class="reference internal" href="../reference/instance_options/">Instance options</a></li>
<li class="toctree-l3 has-children"><a class="reference internal" href="../reference/devices/">Devices</a><input aria-label="Toggle navigation of Devices" class="toctree-checkbox" id="toctree-checkbox-17" name="toctree-checkbox-17" role="switch" type="checkbox"/><label for="toctree-checkbox-17"><span class="icon"><svg><use href="#svg-arrow-right"></use></svg></span></label><ul>
<li class="toctree-l4"><a class="reference internal" href="../reference/standard_devices/">Standard devices</a></li>
<li class="toctree-l4"><a class="reference internal" href="../reference/devices_none/">Type: <code class="docutils literal notranslate"><span class="pre">none</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../reference/devices_nic/">Type: <code class="docutils literal notranslate"><span class="pre">nic</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../reference/devices_disk/">Type: <code class="docutils literal notranslate"><span class="pre">disk</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../reference/devices_unix_char/">Type: <code class="docutils literal notranslate"><span class="pre">unix-char</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../reference/devices_unix_block/">Type: <code class="docutils literal notranslate"><span class="pre">unix-block</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../reference/devices_usb/">Type: <code class="docutils literal notranslate"><span class="pre">usb</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../reference/devices_gpu/">Type: <code class="docutils literal notranslate"><span class="pre">gpu</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../reference/devices_infiniband/">Type: <code class="docutils literal notranslate"><span class="pre">infiniband</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../reference/devices_proxy/">Type: <code class="docutils literal notranslate"><span class="pre">proxy</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../reference/devices_unix_hotplug/">Type: <code class="docutils literal notranslate"><span class="pre">unix-hotplug</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../reference/devices_tpm/">Type: <code class="docutils literal notranslate"><span class="pre">tpm</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../reference/devices_pci/">Type: <code class="docutils literal notranslate"><span class="pre">pci</span></code></a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="../reference/instance_units/">Units for storage and network limits</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../reference/preseed_yaml_fields/">Preseed YAML file fields</a></li>
<li class="toctree-l2"><a class="reference internal" href="../reference/projects/">Project configuration</a></li>
<li class="toctree-l2 has-children"><a class="reference internal" href="../reference/storage_drivers/">Storage drivers</a><input aria-label="Toggle navigation of Storage drivers" class="toctree-checkbox" id="toctree-checkbox-18" name="toctree-checkbox-18" role="switch" type="checkbox"/><label for="toctree-checkbox-18"><span class="icon"><svg><use href="#svg-arrow-right"></use></svg></span></label><ul>
<li class="toctree-l3"><a class="reference internal" href="../reference/storage_dir/">Directory - <code class="docutils literal notranslate"><span class="pre">dir</span></code></a></li>
<li class="toctree-l3"><a class="reference internal" href="../reference/storage_btrfs/">Btrfs - <code class="docutils literal notranslate"><span class="pre">btrfs</span></code></a></li>
<li class="toctree-l3"><a class="reference internal" href="../reference/storage_lvm/">LVM - <code class="docutils literal notranslate"><span class="pre">lvm</span></code></a></li>
<li class="toctree-l3"><a class="reference internal" href="../reference/storage_zfs/">ZFS - <code class="docutils literal notranslate"><span class="pre">zfs</span></code></a></li>
<li class="toctree-l3"><a class="reference internal" href="../reference/storage_ceph/">Ceph RBD - <code class="docutils literal notranslate"><span class="pre">ceph</span></code></a></li>
<li class="toctree-l3"><a class="reference internal" href="../reference/storage_powerflex/">Dell PowerFlex - <code class="docutils literal notranslate"><span class="pre">powerflex</span></code></a></li>
<li class="toctree-l3"><a class="reference internal" href="../reference/storage_pure/">Pure Storage - <code class="docutils literal notranslate"><span class="pre">pure</span></code></a></li>
<li class="toctree-l3"><a class="reference internal" href="../reference/storage_alletra/">HPE Alletra - <code class="docutils literal notranslate"><span class="pre">alletra</span></code></a></li>
<li class="toctree-l3"><a class="reference internal" href="../reference/storage_cephfs/">CephFS - <code class="docutils literal notranslate"><span class="pre">cephfs</span></code></a></li>
<li class="toctree-l3"><a class="reference internal" href="../reference/storage_cephobject/">Ceph Object - <code class="docutils literal notranslate"><span class="pre">cephobject</span></code></a></li>
</ul>
</li>
<li class="toctree-l2 has-children"><a class="reference internal" href="../reference/networks/">Networks</a><input aria-label="Toggle navigation of Networks" class="toctree-checkbox" id="toctree-checkbox-19" name="toctree-checkbox-19" role="switch" type="checkbox"/><label for="toctree-checkbox-19"><span class="icon"><svg><use href="#svg-arrow-right"></use></svg></span></label><ul>
<li class="toctree-l3"><a class="reference internal" href="../reference/network_bridge/">Bridge network</a></li>
<li class="toctree-l3"><a class="reference internal" href="../reference/network_ovn/">OVN network</a></li>
<li class="toctree-l3"><a class="reference internal" href="../reference/network_macvlan/">Macvlan network</a></li>
<li class="toctree-l3"><a class="reference internal" href="../reference/network_physical/">Physical network</a></li>
<li class="toctree-l3"><a class="reference internal" href="../reference/network_sriov/">SR-IOV network</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../reference/cluster_member_config/">Cluster configuration</a></li>
<li class="toctree-l2"><a class="reference internal" href="../reference/placement_groups/">Placement group configuration</a></li>
<li class="toctree-l2"><a class="reference internal" href="../reference/server_settings/">Production server settings</a></li>
<li class="toctree-l2"><a class="reference internal" href="../reference/provided_metrics/">Provided metrics</a></li>
<li class="toctree-l2"><a class="reference internal" href="../reference/permissions/">Permissions</a></li>
<li class="toctree-l2 has-children"><a class="reference internal" href="../restapi_landing/">REST API</a><input aria-label="Toggle navigation of REST API" class="toctree-checkbox" id="toctree-checkbox-20" name="toctree-checkbox-20" role="switch" type="checkbox"/><label for="toctree-checkbox-20"><span class="icon"><svg><use href="#svg-arrow-right"></use></svg></span></label><ul>
<li class="toctree-l3"><a class="reference internal" href="../rest-api/">Main API documentation</a></li>
<li class="toctree-l3"><a class="reference internal" href="../api/">Main API specification</a></li>
<li class="toctree-l3"><a class="reference internal" href="../api-extensions/">Main API extensions</a></li>
<li class="toctree-l3"><a class="reference internal" href="../events/">Events API documentation</a></li>
<li class="toctree-l3"><a class="reference internal" href="../dev-lxd/">Instance API</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../reference/driver_csi/">LXD CSI driver reference</a></li>
<li class="toctree-l2 has-children"><a class="reference internal" href="../reference/manpages/">Man pages</a><input aria-label="Toggle navigation of Man pages" class="toctree-checkbox" id="toctree-checkbox-21" name="toctree-checkbox-21" role="switch" type="checkbox"/><label for="toctree-checkbox-21"><span class="icon"><svg><use href="#svg-arrow-right"></use></svg></span></label><ul>
<li class="toctree-l3"><a class="reference internal" href="../reference/manpages/lxc/"><code class="docutils literal notranslate"><span class="pre">lxc</span></code></a></li>
</ul>
</li>
<li class="toctree-l2 has-children"><a class="reference internal" href="../internals/">Internals</a><input aria-label="Toggle navigation of Internals" class="toctree-checkbox" id="toctree-checkbox-22" name="toctree-checkbox-22" role="switch" type="checkbox"/><label for="toctree-checkbox-22"><span class="icon"><svg><use href="#svg-arrow-right"></use></svg></span></label><ul>
<li class="toctree-l3"><a class="reference internal" href="../environment/">Environment variables</a></li>
<li class="toctree-l3"><a class="reference internal" href="../reference/uefi_variables/">UEFI variables for VMs</a></li>
<li class="toctree-l3"><a class="reference internal" href="../daemon-behavior/">Daemon behavior</a></li>
<li class="toctree-l3"><a class="reference internal" href="../syscall-interception/">System call interception</a></li>
<li class="toctree-l3"><a class="reference internal" href="../userns-idmap/">User namespace setup</a></li>
<li class="toctree-l3"><a class="reference internal" href="../reference/ovn-internals/">OVN implementation</a></li>
<li class="toctree-l3"><a class="reference internal" href="../reference/vm_live_migration_internals/">VM live migration implementation</a></li>
<li class="toctree-l3"><a class="reference internal" href="../reference/dqlite-internals/">Dqlite</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference external" href="https://github.com/canonical/lxd">Project repository</a></li>
<li class="toctree-l2"><a class="reference external" href="https://images.lxd.canonical.com">Image server</a></li>
</ul>
</li>
</ul>

</div>
</div>

      </div>
      
    </div>
  </aside>
  <div class="main">
    <div class="content">
      <div class="article-container">
        <a href="#" class="back-to-top muted-link">
          <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
            <path d="M13 20h-2V8l-5.5 5.5-1.42-1.42L12 4.16l7.92 7.92-1.42 1.42L13 8v12z"></path>
          </svg>
          <span>Back to top</span>
        </a>
        <div class="content-icon-container">
          <div class="edit-this-page">
  <a class="muted-link" href="https://github.com/canonical/lxd/edit/main/doc/cloud-init.md" title="Contribute to this page">
    <svg><use href="#svg-pencil"></use></svg>
    <span class="visually-hidden">Contribute to this page</span>
  </a>
</div><div class="theme-toggle-container theme-toggle-content">
            <button class="theme-toggle" aria-label="Toggle Light / Dark / Auto color theme">
              <svg class="theme-icon-when-auto-light"><use href="#svg-sun-with-moon"></use></svg>
              <svg class="theme-icon-when-auto-dark"><use href="#svg-moon-with-sun"></use></svg>
              <svg class="theme-icon-when-dark"><use href="#svg-moon"></use></svg>
              <svg class="theme-icon-when-light"><use href="#svg-sun"></use></svg>
            </button>
          </div>
          <label class="toc-overlay-icon toc-content-icon" for="__toc">
            <span class="icon"><svg><use href="#svg-toc"></use></svg></span>
          </label>
        </div>
        <article role="main" id="furo-main-content">
          <section id="how-to-use-cloud-init">
<span id="cloud-init"></span><h1>How to use <code class="docutils literal notranslate"><span class="pre">cloud-init</span></code><a class="headerlink" href="#how-to-use-cloud-init" title="Link to this heading">¶</a></h1>

            <p class="youtube_link">
              <a href="https://www.youtube.com/watch?v=8OCG15TAldI" target="_blank">
                <span title="LXD instance configuration with cloud-init" class="play_icon">▶</span>
                <span title="LXD instance configuration with cloud-init">Watch on YouTube</span>
              </a>
            </p>
        <p><a class="reference external" href="https://cloud-init.io/"><code class="docutils literal notranslate"><span class="pre">cloud-init</span></code></a> is a tool for automatically initializing and customizing an instance of a Linux distribution.</p>
<p>By adding <code class="docutils literal notranslate"><span class="pre">cloud-init</span></code> configuration to your instance, you can instruct <code class="docutils literal notranslate"><span class="pre">cloud-init</span></code> to execute specific actions at the first start of an instance.
Possible actions include, for example:</p>
<ul class="simple">
<li><p>Updating and installing packages</p></li>
<li><p>Applying certain configurations</p></li>
<li><p>Adding users</p></li>
<li><p>Enabling services</p></li>
<li><p>Running commands or scripts</p></li>
<li><p>Automatically growing the file system of a VM to the size (quota) of the disk</p></li>
</ul>
<p>See the <a class="reference external" href="https://docs.cloud-init.io/en/latest/index.html#index" title="(in cloud-init v26.1)"><span>Cloud-init documentation</span></a> for detailed information.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>The <code class="docutils literal notranslate"><span class="pre">cloud-init</span></code> actions are run only once on the first start of the instance.
Rebooting the instance does not re-trigger the actions.</p>
</div>
<section id="cloud-init-support-in-images">
<span id="cloud-init-support"></span><h2><code class="docutils literal notranslate"><span class="pre">cloud-init</span></code> support in images<a class="headerlink" href="#cloud-init-support-in-images" title="Link to this heading">¶</a></h2>
<p>To use <code class="docutils literal notranslate"><span class="pre">cloud-init</span></code>, you must base your instance on an image that has <code class="docutils literal notranslate"><span class="pre">cloud-init</span></code> installed:</p>
<ul class="simple">
<li><p>All images from the <code class="docutils literal notranslate"><span class="pre">ubuntu</span></code> and <code class="docutils literal notranslate"><span class="pre">ubuntu-daily</span></code> <a class="reference internal" href="../reference/remote_image_servers/#remote-image-servers"><span class="std std-ref">image servers</span></a> have <code class="docutils literal notranslate"><span class="pre">cloud-init</span></code> support.
However, images for Ubuntu releases prior to 20.04 LTS require special handling to integrate properly with <code class="docutils literal notranslate"><span class="pre">cloud-init</span></code>, so that <code class="docutils literal notranslate"><span class="pre">lxc</span> <span class="pre">exec</span></code> works correctly with virtual machines that use those images. Refer to <a class="reference internal" href="../reference/devices_disk/#vm-cloud-init-config"><span class="std std-ref">VM <code class="docutils literal notranslate"><span class="pre">cloud-init</span></code></span></a>.</p></li>
<li><p>Images from the <a class="reference external" href="https://images.lxd.canonical.com/"><code class="docutils literal notranslate"><span class="pre">images</span></code> remote</a> have <code class="docutils literal notranslate"><span class="pre">cloud-init</span></code>-enabled variants, which are usually bigger in size than the default variant.
The cloud variants use the <code class="docutils literal notranslate"><span class="pre">/cloud</span></code> suffix, for example, <code class="docutils literal notranslate"><span class="pre">images:alpine/edge/cloud</span></code>.</p></li>
</ul>
</section>
<section id="configuration-options">
<h2>Configuration options<a class="headerlink" href="#configuration-options" title="Link to this heading">¶</a></h2>
<p>LXD supports two different sets of configuration options for configuring <code class="docutils literal notranslate"><span class="pre">cloud-init</span></code>: <code class="docutils literal notranslate"><span class="pre">cloud-init.*</span></code> and <code class="docutils literal notranslate"><span class="pre">user.*</span></code>.
Which of these sets you must use depends on the <code class="docutils literal notranslate"><span class="pre">cloud-init</span></code> support in the image that you use.
As a rule of thumb, newer images support the <code class="docutils literal notranslate"><span class="pre">cloud-init.*</span></code> configuration options, while older images support <code class="docutils literal notranslate"><span class="pre">user.*</span></code>.
However, there might be exceptions to that rule.</p>
<p>The following configuration options are supported:</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">cloud-init.vendor-data</span></code> or <code class="docutils literal notranslate"><span class="pre">user.vendor-data</span></code> (see <a class="reference external" href="https://docs.cloud-init.io/en/latest/explanation/vendordata.html#vendor-data" title="(in cloud-init v26.1)"><span>Vendor-data</span></a>)</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">cloud-init.user-data</span></code> or <code class="docutils literal notranslate"><span class="pre">user.user-data</span></code> (see <a class="reference external" href="https://docs.cloud-init.io/en/latest/explanation/format/index.html#user-data-formats" title="(in cloud-init v26.1)"><span>User-data formats</span></a>)</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">cloud-init.network-config</span></code> or <code class="docutils literal notranslate"><span class="pre">user.network-config</span></code> (see <a class="reference external" href="https://docs.cloud-init.io/en/latest/reference/network-config.html#network-config" title="(in cloud-init v26.1)"><span>Network configuration</span></a>)</p></li>
</ul>
<p>For more information about the configuration options, see the <a class="reference internal" href="../reference/instance_options/#instance-options-cloud-init"><span class="std std-ref"><code class="docutils literal notranslate"><span class="pre">cloud-init</span></code> instance options</span></a>, and the documentation for the <a class="reference external" href="https://docs.cloud-init.io/en/latest/reference/datasources/lxd.html#datasource-lxd" title="(in cloud-init v26.1)"><span class="xref std std-ref">LXD data source</span></a> in the <code class="docutils literal notranslate"><span class="pre">cloud-init</span></code> documentation.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Ubuntu 20.04 and earlier have recent versions of the <code class="docutils literal notranslate"><span class="pre">cloud-init</span></code> package but support for the modern <code class="docutils literal notranslate"><span class="pre">cloud-init.*</span></code> configuration options is disabled in those series. As such, when using such old instances, remember to use the <code class="docutils literal notranslate"><span class="pre">user.*</span></code> configuration options instead.</p>
</div>
<section id="vendor-data-and-user-data">
<h3>Vendor data and user data<a class="headerlink" href="#vendor-data-and-user-data" title="Link to this heading">¶</a></h3>
<p>Both <code class="docutils literal notranslate"><span class="pre">vendor-data</span></code> and <code class="docutils literal notranslate"><span class="pre">user-data</span></code> are used to provide <a class="reference external" href="https://docs.cloud-init.io/en/latest/explanation/format/cloud-config.html#user-data-formats-cloud-config" title="(in cloud-init v26.1)"><span class="xref std std-ref">cloud configuration data</span></a> to <code class="docutils literal notranslate"><span class="pre">cloud-init</span></code>.</p>
<p>The main idea is that <code class="docutils literal notranslate"><span class="pre">vendor-data</span></code> is used for the general default configuration, while <code class="docutils literal notranslate"><span class="pre">user-data</span></code> is used for instance-specific configuration.
This means that you should specify <code class="docutils literal notranslate"><span class="pre">vendor-data</span></code> in a profile and <code class="docutils literal notranslate"><span class="pre">user-data</span></code> in the instance configuration.
LXD does not enforce this method, but allows using both <code class="docutils literal notranslate"><span class="pre">vendor-data</span></code> and <code class="docutils literal notranslate"><span class="pre">user-data</span></code> in profiles and in the instance configuration.</p>
<p>If both <code class="docutils literal notranslate"><span class="pre">vendor-data</span></code> and <code class="docutils literal notranslate"><span class="pre">user-data</span></code> are supplied for an instance, <code class="docutils literal notranslate"><span class="pre">cloud-init</span></code> merges the two configurations.
However, if you use the same keys in both configurations, merging might not be possible.
In this case, configure how <code class="docutils literal notranslate"><span class="pre">cloud-init</span></code> should merge the provided data.
See <a class="reference external" href="https://docs.cloud-init.io/en/latest/reference/merging.html#merging-user-data" title="(in cloud-init v26.1)"><span>Merging cloud-config</span></a> for instructions.</p>
</section>
</section>
<section id="how-to-configure-cloud-init">
<h2>How to configure <code class="docutils literal notranslate"><span class="pre">cloud-init</span></code><a class="headerlink" href="#how-to-configure-cloud-init" title="Link to this heading">¶</a></h2>
<p>To configure <code class="docutils literal notranslate"><span class="pre">cloud-init</span></code> for an instance, add the corresponding configuration options to a <a class="reference internal" href="../profiles/#profiles"><span class="std std-ref">profile</span></a> that the instance uses or directly to the <a class="reference internal" href="../howto/instances_configure/#instances-configure"><span class="std std-ref">instance configuration</span></a>.</p>
<p>When configuring <code class="docutils literal notranslate"><span class="pre">cloud-init</span></code> directly for an instance, keep in mind that <code class="docutils literal notranslate"><span class="pre">cloud-init</span></code> runs only on instance start.
This means any changes to <code class="docutils literal notranslate"><span class="pre">cloud-init</span></code> configuration only take effect after the next instance start. To ensure <code class="docutils literal notranslate"><span class="pre">cloud-init</span></code> configurations are applied on every boot, LXD changes the instance ID whenever relevant <code class="docutils literal notranslate"><span class="pre">cloud-init</span></code> configuration keys are modified. This triggers <code class="docutils literal notranslate"><span class="pre">cloud-init</span></code> to fetch and apply the updated data from LXD as if it were the instance’s first boot. For more information, see the <code class="docutils literal notranslate"><span class="pre">cloud-init</span></code> docs regarding <a class="reference external" href="https://docs.cloud-init.io/en/latest/explanation/first_boot.html#first-boot-determination" title="(in cloud-init v26.1)"><span>First boot determination</span></a>.</p>
<p>To add your configuration:</p>
<div class="sphinx-tabs docutils container">
<div aria-label="Tabbed content" class="closeable" role="tablist"><button aria-controls="panel-0-Q0xJ" aria-selected="true" class="sphinx-tabs-tab group-tab" id="tab-0-Q0xJ" name="Q0xJ" role="tab" tabindex="0">CLI</button><button aria-controls="panel-0-QVBJ" aria-selected="false" class="sphinx-tabs-tab group-tab" id="tab-0-QVBJ" name="QVBJ" role="tab" tabindex="-1">API</button><button aria-controls="panel-0-VUk=" aria-selected="false" class="sphinx-tabs-tab group-tab" id="tab-0-VUk=" name="VUk=" role="tab" tabindex="-1">UI</button></div><div aria-labelledby="tab-0-Q0xJ" class="sphinx-tabs-panel group-tab" id="panel-0-Q0xJ" name="Q0xJ" role="tabpanel" tabindex="0"><p>Write the configuration to a file and pass that file to the <code class="docutils literal notranslate"><span class="pre">lxc</span> <span class="pre">config</span></code> command.
For example, create <code class="docutils literal notranslate"><span class="pre">cloud-init.yml</span></code> with the following content:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>#cloud-config
package_upgrade: true
packages:
  - package1
  - package2
</pre></div>
</div>
<p>Then run the following command:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>lxc config set &lt;instance_name&gt; cloud-init.user-data - &lt; cloud-init.yml
</pre></div>
</div>
</div><div aria-labelledby="tab-0-QVBJ" class="sphinx-tabs-panel group-tab" hidden="true" id="panel-0-QVBJ" name="QVBJ" role="tabpanel" tabindex="0"><p>Provide the <code class="docutils literal notranslate"><span class="pre">cloud-init</span></code> configuration as a string with escaped newline characters.</p>
<p>For example:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>lxc query --request PATCH /1.0/instances/&lt;instance_name&gt; --data &#39;{
  &quot;config&quot;: {
    &quot;cloud-init.user-data&quot;: &quot;#cloud-config\npackage_upgrade: true\npackages:\n  - package1\n  - package2&quot;
  }
}&#39;
</pre></div>
</div>
<p>Alternatively, to avoid mistakes, write the configuration to a file and include that in your request.
For example, create <code class="docutils literal notranslate"><span class="pre">cloud-init.txt</span></code> with the following content:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>#cloud-config
package_upgrade: true
packages:
  - package1
  - package2
</pre></div>
</div>
<p>Then send the following request:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>lxc query --request PATCH /1.0/instances/&lt;instance_name&gt; --data &#39;{
&quot;config&quot;: {
  &quot;cloud-init.user-data&quot;: &quot;&#39;&quot;$(awk -v ORS=&#39;\\n&#39; &#39;1&#39; cloud-init.txt)&quot;&#39;&quot;
  }
}&#39;
</pre></div>
</div>
</div><div aria-labelledby="tab-0-VUk=" class="sphinx-tabs-panel group-tab" hidden="true" id="panel-0-VUk=" name="VUk=" role="tabpanel" tabindex="0"><p>Go to the <span class="guilabel">Configuration</span> tab of the instance detail page and select <span class="guilabel">Advanced &gt; Cloud init</span>.
Then click <span class="guilabel">Edit instance</span> and override the configuration for one or more of the <code class="docutils literal notranslate"><span class="pre">cloud-init</span></code> configuration options.</p>
</div></div>
<section id="yaml-format-for-cloud-init-configuration">
<h3>YAML format for <code class="docutils literal notranslate"><span class="pre">cloud-init</span></code> configuration<a class="headerlink" href="#yaml-format-for-cloud-init-configuration" title="Link to this heading">¶</a></h3>
<p>The <code class="docutils literal notranslate"><span class="pre">cloud-init</span></code> options require YAML’s <a class="reference external" href="https://yaml.org/spec/1.2.2/#812-literal-style">literal style format</a>.
You use a pipe symbol (<code class="docutils literal notranslate"><span class="pre">|</span></code>) to indicate that all indented text after the pipe should be passed to <code class="docutils literal notranslate"><span class="pre">cloud-init</span></code> as a single string, with new lines and indentation preserved.</p>
<p>The <code class="docutils literal notranslate"><span class="pre">vendor-data</span></code> and <code class="docutils literal notranslate"><span class="pre">user-data</span></code> options usually start with <code class="docutils literal notranslate"><span class="pre">#cloud-config</span></code>. But <code class="docutils literal notranslate"><span class="pre">cloud-init</span></code> has an array of <a class="reference external" href="https://docs.cloud-init.io/en/latest/explanation/format/index.html#user-data-formats" title="(in cloud-init v26.1)"><span class="xref std std-ref">configuration types</span></a> available.</p>
<p>For example:</p>
<div class="highlight-yaml notranslate"><div class="highlight"><pre><span></span><span class="nt">config</span><span class="p">:</span>
<span class="w">  </span><span class="nt">cloud-init.user-data</span><span class="p">:</span><span class="w"> </span><span class="p p-Indicator">|</span>
<span class="w">    </span><span class="no">#cloud-config</span>
<span class="w">    </span><span class="no">package_upgrade: true</span>
<span class="w">    </span><span class="no">packages:</span>
<span class="w">      </span><span class="no">- package1</span>
<span class="w">      </span><span class="no">- package2</span>
</pre></div>
</div>
<div class="highlight-yaml notranslate"><div class="highlight"><pre><span></span><span class="nt">config</span><span class="p">:</span>
<span class="w">  </span><span class="nt">cloud-init.user-data</span><span class="p">:</span><span class="w"> </span><span class="p p-Indicator">|</span>
<span class="w">    </span><span class="no">#!/usr/bin/bash</span>
<span class="w">    </span><span class="no">echo hello | tee -a /tmp/example.txt</span>
</pre></div>
</div>
<div class="admonition tip">
<p class="admonition-title">Tip</p>
<p>See <a class="reference external" href="https://docs.cloud-init.io/en/latest/howto/debug_user_data.html#check-user-data-cloud-config" title="(in cloud-init v26.1)"><span class="xref std std-ref">How to validate user data</span></a> for information on how to check whether the syntax is correct.</p>
</div>
</section>
</section>
<section id="how-to-check-the-cloud-init-status">
<h2>How to check the <code class="docutils literal notranslate"><span class="pre">cloud-init</span></code> status<a class="headerlink" href="#how-to-check-the-cloud-init-status" title="Link to this heading">¶</a></h2>
<p><code class="docutils literal notranslate"><span class="pre">cloud-init</span></code> runs automatically on the first start of an instance.
Depending on the configured actions, it might take a while until it finishes.</p>
<p>To check the <code class="docutils literal notranslate"><span class="pre">cloud-init</span></code> status, log on to the instance and enter the following command:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>cloud-init status
</pre></div>
</div>
<p>If the result is <code class="docutils literal notranslate"><span class="pre">status:</span> <span class="pre">running</span></code>, <code class="docutils literal notranslate"><span class="pre">cloud-init</span></code> is still working. If the result is <code class="docutils literal notranslate"><span class="pre">status:</span> <span class="pre">done</span></code>, it has finished.</p>
<p>Alternatively, use the <code class="docutils literal notranslate"><span class="pre">--wait</span></code> flag to be notified only when <code class="docutils literal notranslate"><span class="pre">cloud-init</span></code> is finished:</p>
<div class="terminal docutils container">
<div class="input docutils container">
<div class="prompt docutils container">
<code class="docutils literal notranslate"><span class="pre">root&#64;instance:~#</span> </code></div>
<span class="command"><code class="docutils literal notranslate"><span class="pre">cloud-init</span> <span class="pre">status</span> <span class="pre">--wait</span>
</code></span></div>
<div class="terminal-code highlight-text notranslate"><div class="highlight"><pre><span></span>.....................................
status: done
</pre></div>
</div>
</div>
</section>
<section id="how-to-specify-user-or-vendor-data">
<h2>How to specify user or vendor data<a class="headerlink" href="#how-to-specify-user-or-vendor-data" title="Link to this heading">¶</a></h2>
<p>The <code class="docutils literal notranslate"><span class="pre">user-data</span></code> and <code class="docutils literal notranslate"><span class="pre">vendor-data</span></code> configuration can be used to, for example, upgrade or install packages, add users, or run commands.</p>
<p>The provided values must have a first line that indicates what type of <a class="reference external" href="https://docs.cloud-init.io/en/latest/explanation/format/index.html#user-data-formats" title="(in cloud-init v26.1)"><span class="xref std std-ref">user data format</span></a> is being passed to <code class="docutils literal notranslate"><span class="pre">cloud-init</span></code>.
For activities like upgrading packages or setting up a user, <code class="docutils literal notranslate"><span class="pre">#cloud-config</span></code> is the data format to use.</p>
<p>The configuration data is stored in the following files in the instance’s root file system:</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">/var/lib/cloud/instance/cloud-config.txt</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">/var/lib/cloud/instance/user-data.txt</span></code></p></li>
</ul>
<section id="examples">
<h3>Examples<a class="headerlink" href="#examples" title="Link to this heading">¶</a></h3>
<p>See the following sections for the user data (or vendor data) configuration for different example use cases.</p>
<p>You can find more advanced <a class="reference external" href="https://docs.cloud-init.io/en/latest/reference/examples.html#yaml-examples" title="(in cloud-init v26.1)"><span class="xref std std-ref">examples</span></a> in the <code class="docutils literal notranslate"><span class="pre">cloud-init</span></code> documentation.</p>
<section id="upgrade-packages">
<h4>Upgrade packages<a class="headerlink" href="#upgrade-packages" title="Link to this heading">¶</a></h4>
<p>To trigger a package upgrade from the repositories for the instance right after the instance is created, use the <code class="docutils literal notranslate"><span class="pre">package_upgrade</span></code> key:</p>
<div class="highlight-yaml notranslate"><div class="highlight"><pre><span></span><span class="nt">config</span><span class="p">:</span>
<span class="w">  </span><span class="nt">cloud-init.user-data</span><span class="p">:</span><span class="w"> </span><span class="p p-Indicator">|</span>
<span class="w">    </span><span class="no">#cloud-config</span>
<span class="w">    </span><span class="no">package_upgrade: true</span>
</pre></div>
</div>
</section>
<section id="install-packages">
<h4>Install packages<a class="headerlink" href="#install-packages" title="Link to this heading">¶</a></h4>
<p>To install specific packages when the instance is set up, use the <code class="docutils literal notranslate"><span class="pre">packages</span></code> key and specify the package names as a list:</p>
<div class="highlight-yaml notranslate"><div class="highlight"><pre><span></span><span class="nt">config</span><span class="p">:</span>
<span class="w">  </span><span class="nt">cloud-init.user-data</span><span class="p">:</span><span class="w"> </span><span class="p p-Indicator">|</span>
<span class="w">    </span><span class="no">#cloud-config</span>
<span class="w">    </span><span class="no">packages:</span>
<span class="w">      </span><span class="no">- git</span>
<span class="w">      </span><span class="no">- openssh-server</span>
</pre></div>
</div>
</section>
<section id="set-the-time-zone">
<h4>Set the time zone<a class="headerlink" href="#set-the-time-zone" title="Link to this heading">¶</a></h4>
<p>To set the time zone for the instance on instance creation, use the <code class="docutils literal notranslate"><span class="pre">timezone</span></code> key:</p>
<div class="highlight-yaml notranslate"><div class="highlight"><pre><span></span><span class="nt">config</span><span class="p">:</span>
<span class="w">  </span><span class="nt">cloud-init.user-data</span><span class="p">:</span><span class="w"> </span><span class="p p-Indicator">|</span>
<span class="w">    </span><span class="no">#cloud-config</span>
<span class="w">    </span><span class="no">timezone: Europe/Rome</span>
</pre></div>
</div>
</section>
<section id="run-commands">
<h4>Run commands<a class="headerlink" href="#run-commands" title="Link to this heading">¶</a></h4>
<p>To run a command (such as writing a marker file), use the <code class="docutils literal notranslate"><span class="pre">runcmd</span></code> key and specify the commands as a list:</p>
<div class="highlight-yaml notranslate"><div class="highlight"><pre><span></span><span class="nt">config</span><span class="p">:</span>
<span class="w">  </span><span class="nt">cloud-init.user-data</span><span class="p">:</span><span class="w"> </span><span class="p p-Indicator">|</span>
<span class="w">    </span><span class="no">#cloud-config</span>
<span class="w">    </span><span class="no">runcmd:</span>
<span class="w">      </span><span class="no">- [touch, /run/cloud.init.ran]</span>
</pre></div>
</div>
</section>
<section id="add-a-user-account">
<h4>Add a user account<a class="headerlink" href="#add-a-user-account" title="Link to this heading">¶</a></h4>
<p>To add a user account, use the <code class="docutils literal notranslate"><span class="pre">users</span></code> key.
See the <a class="reference external" href="https://docs.cloud-init.io/en/latest/reference/examples.html#including-users-and-groups" title="(in cloud-init v26.1)"><span>Including users and groups</span></a> example in the <code class="docutils literal notranslate"><span class="pre">cloud-init</span></code> documentation for details about default users and which keys are supported.</p>
<div class="highlight-yaml notranslate"><div class="highlight"><pre><span></span><span class="nt">config</span><span class="p">:</span>
<span class="w">  </span><span class="nt">cloud-init.user-data</span><span class="p">:</span><span class="w"> </span><span class="p p-Indicator">|</span>
<span class="w">    </span><span class="no">#cloud-config</span>
<span class="w">    </span><span class="no">users:</span>
<span class="w">      </span><span class="no">- name: documentation_example</span>
</pre></div>
</div>
</section>
</section>
</section>
<section id="how-to-specify-network-configuration-data">
<h2>How to specify network configuration data<a class="headerlink" href="#how-to-specify-network-configuration-data" title="Link to this heading">¶</a></h2>
<p>By default, <code class="docutils literal notranslate"><span class="pre">cloud-init</span></code> configures a DHCP client on an instance’s <code class="docutils literal notranslate"><span class="pre">eth0</span></code> interface.
You can define your own network configuration using the <code class="docutils literal notranslate"><span class="pre">network-config</span></code> option to override the default configuration (this is due to how the template is structured).</p>
<p><code class="docutils literal notranslate"><span class="pre">cloud-init</span></code> then renders the relevant network configuration on the system using either <code class="docutils literal notranslate"><span class="pre">ifupdown</span></code> or <code class="docutils literal notranslate"><span class="pre">netplan</span></code>, depending on the Ubuntu release.</p>
<p>The configuration data is stored in the following files in the instance’s root file system:</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">/var/lib/cloud/seed/nocloud-net/network-config</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">/etc/network/interfaces.d/50-cloud-init.cfg</span></code> (if using <code class="docutils literal notranslate"><span class="pre">ifupdown</span></code>)</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">/etc/netplan/50-cloud-init.yaml</span></code> (if using <code class="docutils literal notranslate"><span class="pre">netplan</span></code>)</p></li>
</ul>
<section id="example">
<h3>Example<a class="headerlink" href="#example" title="Link to this heading">¶</a></h3>
<p>To configure a specific network interface with a static IPv4 address and also use a custom name server, use the following configuration:</p>
<div class="highlight-yaml notranslate"><div class="highlight"><pre><span></span><span class="nt">config</span><span class="p">:</span>
<span class="w">  </span><span class="nt">cloud-init.network-config</span><span class="p">:</span><span class="w"> </span><span class="p p-Indicator">|</span>
<span class="w">    </span><span class="no">version: 2</span>
<span class="w">    </span><span class="no">ethernets:</span>
<span class="w">      </span><span class="no">eth1:</span>
<span class="w">        </span><span class="no">addresses:</span>
<span class="w">          </span><span class="no">- 10.10.101.20/24</span>
<span class="w">        </span><span class="no">gateway4: 10.10.101.1</span>
<span class="w">        </span><span class="no">nameservers:</span>
<span class="w">          </span><span class="no">addresses:</span>
<span class="w">            </span><span class="no">- 10.10.10.254</span>
</pre></div>
</div>
</section>
</section>
<section id="how-to-inject-ssh-keys-into-instances">
<h2>How to inject SSH keys into instances<a class="headerlink" href="#how-to-inject-ssh-keys-into-instances" title="Link to this heading">¶</a></h2>
<p>To inject SSH keys into LXD instances for an arbitrary user, use the configuration key <code class="docutils literal notranslate"><span class="pre">cloud-init.ssh-keys.&lt;keyName&gt;</span></code>.</p>
<p>Use the format <code class="docutils literal notranslate"><span class="pre">&lt;user&gt;:&lt;key&gt;</span></code> for its value, where <code class="docutils literal notranslate"><span class="pre">&lt;user&gt;</span></code> is a Linux username and <code class="docutils literal notranslate"><span class="pre">&lt;key&gt;</span></code> can be either a pure SSH public key or an import ID for a key hosted elsewhere. For example, <code class="docutils literal notranslate"><span class="pre">root:gh:githubUser</span></code> and <code class="docutils literal notranslate"><span class="pre">myUser:ssh-keyAlg</span> <span class="pre">publicKeyHash</span></code> are valid values. To prevent a particular SSH key from being inherited from a profile by an instance, edit the instance configuration by setting the <code class="docutils literal notranslate"><span class="pre">cloud-init.ssh-keys.&lt;keyName&gt;</span></code> key that references the target SSH key to <code class="docutils literal notranslate"><span class="pre">none</span></code>, and the key will not be injected.</p>
<p>The contents of the <code class="docutils literal notranslate"><span class="pre">cloud-init.ssh-keys.&lt;keyName&gt;</span></code> keys are merged into both <a class="configref reference internal" href="../reference/instance_options/#instance-cloud-init:cloud-init.vendor-data"><code class="docutils literal notranslate"><span class="pre">cloud-init.vendor-data</span></code></a> and <a class="configref reference internal" href="../reference/instance_options/#instance-cloud-init:cloud-init.user-data"><code class="docutils literal notranslate"><span class="pre">cloud-init.user-data</span></code></a> before being passed to the guest, following the <code class="docutils literal notranslate"><span class="pre">cloud-config</span></code> specification. (See the <a class="reference external" href="https://docs.cloud-init.io/en/latest/reference/index.html" title="(in cloud-init v26.1)"><span class="xref std std-doc">cloud-init reference</span></a> for details.) Therefore, keys defined via <code class="docutils literal notranslate"><span class="pre">cloud-init.ssh-keys.&lt;keyName&gt;</span></code> cannot be applied if LXD cannot parse the existing <code class="docutils literal notranslate"><span class="pre">cloud-init.vendor-data</span></code> and <code class="docutils literal notranslate"><span class="pre">cloud-init.user-data</span></code> for that instance. This might occur if those keys are not in YAML format or contain invalid YAML. Other configuration formats are not yet supported.</p>
<p>You can define SSH keys via <code class="docutils literal notranslate"><span class="pre">cloud-init.vendor-data</span></code> or <code class="docutils literal notranslate"><span class="pre">cloud-init.user-data</span></code> directly. Keys defined using <code class="docutils literal notranslate"><span class="pre">cloud-init.ssh-keys.&lt;keyName&gt;</span></code> do not conflict with those defined in either of those settings. For details on defining SSH keys with <code class="docutils literal notranslate"><span class="pre">cloud-config</span></code>, see <a class="reference external" href="https://docs.cloud-init.io/en/latest/reference/yaml_examples/ssh.html#cce-ssh" title="(in cloud-init v26.1)"><span class="xref std std-ref">the cloud-init documentation for SSH configuration</span></a>. Changing a <code class="docutils literal notranslate"><span class="pre">cloud-init.*</span></code> key does not remove previously applied keys.</p>
<p>Since <code class="docutils literal notranslate"><span class="pre">cloud-init</span></code> only runs on instance start, updates to <code class="docutils literal notranslate"><span class="pre">cloud-init.*</span></code> keys on a running instance only take effect after restart.</p>
<section id="id1">
<h3>Examples<a class="headerlink" href="#id1" title="Link to this heading">¶</a></h3>
<p>The following command injects <code class="docutils literal notranslate"><span class="pre">someuser</span></code>’s key from Launchpad into the newly created <code class="docutils literal notranslate"><span class="pre">container</span></code>:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>lxc<span class="w"> </span>launch<span class="w"> </span>ubuntu:24.04<span class="w"> </span>container<span class="w"> </span>-c<span class="w"> </span>cloud-init.ssh-keys.mykey<span class="o">=</span>root:lp:someuser
</pre></div>
</div>
<p>The example profile configuration below defines a key to be injected on an instance. The injected key enables the owner of the private key to SSH into the instance as a user named <code class="docutils literal notranslate"><span class="pre">user</span></code>:</p>
<div class="highlight-yaml notranslate"><div class="highlight"><pre><span></span><span class="nt">config</span><span class="p">:</span>
<span class="w">  </span><span class="nt">cloud-init.vendor-data</span><span class="p">:</span><span class="w"> </span><span class="p p-Indicator">|</span>
<span class="w">    </span><span class="no">users:</span>
<span class="w">      </span><span class="no">- name: user</span>
<span class="w">        </span><span class="no">ssh_authorized_keys: ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJFDWcYmMrCZdk9JI29bAiHKD90oEUr8tqK5VvoO8Vcj</span>
</pre></div>
</div>
</section>
</section>
</section>

        </article>
      </div>
      <footer>
        
   

<div class="related-pages">
  
  
      
  
  
  <a class="next-page" href="../howto/instances_routed_nic_vm/">
        <div class="page-info">
          <div class="context">
            <span>Next</span>
          </div>
          <div class="title">How to add a routed NIC device to a virtual machine</div>
        </div>
        <svg class="furo-related-icon"><use href="#svg-arrow-right"></use></svg>
      </a>
    <a class="prev-page" href="../instance-exec/">
        <svg class="furo-related-icon"><use href="#svg-arrow-right"></use></svg>
        <div class="page-info">
          <div class="context">
            <span>Previous</span>
          </div>
          
            <div class="title">How to run commands in an instance</div>
          
        </div>
      </a>
</div>
<div class="bottom-of-page">
  <div class="left-details">
    <div class="copyright">
        &copy; 2014-2026 AGPL-3.0, LXD contributors 
    </div><div class="last-updated">
      Last updated on Feb 12, 2026</div>
  </div>
  <div class="right-details">
    
      <a href="" class="js-revoke-cookie-manager muted-link">Manage your tracker settings</a>
</div>

      </footer>
    </div>
    <aside class="toc-drawer">
      
<div class="toc-sticky toc-scroll">
   
    <div class="toc-title-container">
      <span class="toc-title">
       Contents
      </span>
    </div>
    <div class="toc-tree-container">
      <div class="toc-tree">
        <ul>
<li><a class="reference internal" href="#">How to use <code class="docutils literal notranslate"><span class="pre">cloud-init</span></code></a><ul>
<li><a class="reference internal" href="#cloud-init-support-in-images"><code class="docutils literal notranslate"><span class="pre">cloud-init</span></code> support in images</a></li>
<li><a class="reference internal" href="#configuration-options">Configuration options</a><ul>
<li><a class="reference internal" href="#vendor-data-and-user-data">Vendor data and user data</a></li>
</ul>
</li>
<li><a class="reference internal" href="#how-to-configure-cloud-init">How to configure <code class="docutils literal notranslate"><span class="pre">cloud-init</span></code></a><ul>
<li><a class="reference internal" href="#yaml-format-for-cloud-init-configuration">YAML format for <code class="docutils literal notranslate"><span class="pre">cloud-init</span></code> configuration</a></li>
</ul>
</li>
<li><a class="reference internal" href="#how-to-check-the-cloud-init-status">How to check the <code class="docutils literal notranslate"><span class="pre">cloud-init</span></code> status</a></li>
<li><a class="reference internal" href="#how-to-specify-user-or-vendor-data">How to specify user or vendor data</a><ul>
<li><a class="reference internal" href="#examples">Examples</a><ul>
<li><a class="reference internal" href="#upgrade-packages">Upgrade packages</a></li>
<li><a class="reference internal" href="#install-packages">Install packages</a></li>
<li><a class="reference internal" href="#set-the-time-zone">Set the time zone</a></li>
<li><a class="reference internal" href="#run-commands">Run commands</a></li>
<li><a class="reference internal" href="#add-a-user-account">Add a user account</a></li>
</ul>
</li>
</ul>
</li>
<li><a class="reference internal" href="#how-to-specify-network-configuration-data">How to specify network configuration data</a><ul>
<li><a class="reference internal" href="#example">Example</a></li>
</ul>
</li>
<li><a class="reference internal" href="#how-to-inject-ssh-keys-into-instances">How to inject SSH keys into instances</a><ul>
<li><a class="reference internal" href="#id1">Examples</a></li>
</ul>
</li>
</ul>
</li>
</ul>

      </div>
    </div>
   
    
    <div class="relatedlinks-title-container">
      <span class="relatedlinks-title">
       Related links
      </span>
    </div>
    <div class="relatedlinks-container">
      <div class="relatedlinks">
        
          <ul><li><a href="https://discuss.linuxcontainers.org/t/12559" target="_blank">First&#32;class&#32;cloud-init&#32;support</a></li></ul>
        
        
          <ul><li><a href="https://cloudinit.readthedocs.org/" target="_blank">Cloud-init&#32;documentation</a></li></ul>
        
      </div>
    </div>
    
  </div>

    </aside>
  </div>
</div><script src="../_static/jquery.js?v=5d32c60e"></script>
    <script src="../_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
    <script src="../_static/documentation_options.js?v=a5603611"></script>
    <script src="../_static/doctools.js?v=9a2dae69"></script>
    <script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
    <script src="../_static/scripts/furo.js?v=46bd48cc"></script>
    <script src="../_static/clipboard.min.js?v=a7894cd8"></script>
    <script src="../_static/copybutton.js?v=b01cb6f2"></script>
    <script src="../_static/config-options.js"></script>
    <script src="../_static/design-tabs.js?v=f930bc37"></script>
    <script src="../_static/tabs.js?v=3030b3cb"></script>
    <script src="../_static/js/bundle.js?v=a4d88309"></script>
    <script src="../_static/header-nav.js?v=e117ad08"></script>
    <script src="../_static/github_issue_links.js?v=32bb732f"></script>
    
<script>
  const github_url = "https://github.com/canonical/lxd";
</script>
</body>
</html>