Search code examples
ubuntucloud-initubuntu-20.04

How do I set a custom password with Cloud-init on Ubuntu 20.04?


Recently I've gotten Cloud-Init to work by mounting my config in an image. This is all fine, it works. If I break the config, it tells me. What it doesn't tell me is why I'm not allowed to log on.

What I've tried is creating my own password using echo possible | mkpasswd -m sha-512 -s and by copying the example found on the quickstart page: https://wiki.ubuntu.com/FoundationsTeam/AutomatedServerInstalls/QuickStart

Neither work. I've tried setting a custom username too. Doesn't change anything. The default ubuntu:ubuntu is also unavailable. Neither is ubuntu and blank.

What I'm using:

https://releases.ubuntu.com/20.04/ubuntu-20.04-live-server-amd64.iso

https://wiki.ubuntu.com/FoundationsTeam/AutomatedServerInstalls/QuickStart

# echo possible | mkpasswd -m sha-512 -s                                    
$6$nqZiIASVBA.iF$9nubU0ImWVrv4XhtEq9XhSh9UYNFQ7yC9Lf7A.uheSlJ3cgI5d9ltkUwRq.X8lAwoQuLAMem6v.gJNGYwk5XA0

The following config with it's supplied password, or the above;

#cloud-config
autoinstall:
  version: 1
  identity:
    hostname: ubuntu-server
    password: "$6$exDY1mhS4KUYCE/2$zmn9ToZwTKLhCw.b4/b.ZRTIZM30JZ4QrOQ2aOXJ8yk96xpcCof0kxKwuX1kqLG/ygbJ1f8wxED22bTL4F46P0"
    username: ubuntu

I've also tried setting up a users block like this:

https://gist.github.com/leogallego/a614c61457ed22cb1d960b32de4a1b01#file-ubuntu-cloud-virtualbox-sh-L46-L56

What I'm asking for:

  • A better documentation of what type of hash is expected.
  • A working user-data config

Solution

  • I've finally found a working config that creates a usable account;

    users:
      - default
      - name: kim
        passwd: "$6$kW4vfBM9kGgq4hr$TFtHW7.3jOECR9UCBuw9NrdSMJETzSVoNQGcVv2y.RqRUzWDEtYhYRkGvIpB6ml1fh/fZEVIgKbSXI9L1B6xF."
        shell: /bin/bash
        lock-passwd: false
        ssh_pwauth: True
        chpasswd: { expire: False }
        sudo: ALL=(ALL) NOPASSWD:ALL
        groups: users, admin
        ssh_authorized_keys:
         - ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCbJ7oF5RXUj6R1ewF15X2i6RieWFmVUkOyT0DwzgfI8fRl5mMMSRlDRYQi3NznwcWDAxLApF82FomNv8vk1V2SXDGGs8XpOvtgAPpR3JUKJGmxoiES7rxa7bq/JSmpGprsnlCocTJnOfDz6Gz2Ge4+D84EZHOW7ejbkWDBdXOYYRMIlRSoXBkb0017G/OIvPNdwZRYLzLJYjGGL08GX+/Da+lrbz8/FaewXwb/BfjRYESOG+aJNTCOQfgzNsFGJ6EslsMc1bDtCq2pvWUenlUo/2BEAICiJxmXZkAjDrIYcyTzHLE14+UfCiC6pbMEdXF2ndUARr0HcNpvJz8K0Mg4CfjRpxaopfPfHp/lMR36ys0r4bT3q9iU4ClnUAeWxbCK7pUN+D/6TVrIKLOLuuIph81sb5+jW23ycg0fjQ/2/ttKQvTzHwomN6B6T/KgXVt367Iq+uzN02wtk282pJOIIqVi3PSHVcJl1I+bFAzeEdmJP29d/wnp0ZyuNYDp0P8= miesl@mies-pc
    
    autoinstall:
        version: 1
        identity:
            hostname: yamanouchi-node-1
            username: ubuntu
            password: "$6$exDY1mhS4KUYCE/2$zmn9ToZwTKLhCw.b4/b.ZRTIZM30JZ4QrOQ2aOXJ8yk96xpcCof0kxKwuX1kqLG/ygbJ1f8wxED22bTL4F46P0"
        refresh-installer:
            update: yes
    

    It creates a user with name kim and password possible. I'm not entirely sure whether refresh-installer is required (I don't think so). It's insanely insecure with password ssh and no password root, but hey. You can configure that yourself.

    The ubuntu account remains unusable. I'm at a loss as to why.