3

I have seen, that the ubuntu-server autoinstaller sets a random ssh password and key to be able to connect via installation phase. But i now want to setup a headless system, so I cannot see the random password. Is there a way to configure this password or a own public key ?

Peter smith
  • 73
  • 2
  • 5

1 Answers1

3

Yes. Here is a snippet that can be added to the autoinstall user-data file. It will set the password for the installer user and install an authorized_key for the installer user. This config must be added at the root level. The same level as the autoinstall: key, not part of the autoinstall: section.

# set password to r00tme
chpasswd:
    expire: false
    list:
        - installer:$6$.c38i4RIqZeF4RtR$hRu2RFep/.6DziHLnRqGOEImb15JT2i.K/F9ojBkK/79zqY30Ll2/xx6QClQfdelLe.ZjpeVYfE8xBBcyLspa/
ssh_authorized_keys:
    - ssh-rsa FILLINYOUROWNKEYHERE installer

How it works

When the installer boots, it uses cloud-init to configure the installer environment. The autoinstall user-data file is really just a cloud-init config used to configure this environment.

In the installer, the default cloud-init configuration will generate an installer user by default

   default_user:
     name: installer
     lock_passwd: false
     gecos: Ubuntu
     groups: [adm, audio, cdrom, dialout, dip, floppy, lxd, netdev, plugdev, sudo, video]
     sudo: ["ALL=(ALL) NOPASSWD:ALL"]
     shell: /usr/bin/subiquity-shell

and will assign the installer user a random password

chpasswd:
    expire: false
    list:
        - installer:RANDOM

By providing configuration within the autoinstall file, it will override the default config.

Another method would be to provide user info within the autoinstall file. This will let you more explicitly control the properties of the created user(s).