Creating new ssh sudo user fails for ubuntu/focal but not centos/8/cloud

I am using the following profile to attempt creating an ansible-friendly user on bothCentOS and Ubuntu platforms:

% lxc profile show $this_profile
config:
  user.user-data: |
    #cloud-config
    locale: en_AU.UTF-8
    timezone: Australia/Sydney
    package_upgrade: true
    packages: sudo
    users:
      - name: lnxcfg
        groups: sudo
        shell: /usr/bin/bash
        sudo: ['ALL=(ALL) NOPASSWD:ALL']
        ssh_authorized_keys:
          - ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIACBSmFgMek1WjJif8W2Iz4W9YoVMu9wCfiTja+GJq3h ansible
description: ansible-friendly profile
devices: {}
name: ansible-test
used_by:
- /1.0/instances/ansible-test-ansible

I create instances thus:

lxc launch images:ubuntu/focal/cloud --profile default --profile ansible-test $c1

I previously tried images:ubuntu/focal but there were no logs in /var/log/cloud-init*.

Is images:ubuntu/focal/ using a stripped down cloud-init? I have previously used #cloud-config to install ssh-keys and x-11/CUDA support.

lxc exec $c1 -- su --login 
root@ansible-test-ansible:~# cloud-init analyze show
-- Boot Record 01 --
The total time elapsed since completing an event is printed after the "@" character.
The time the event takes is printed after the "+" character.

Starting stage: init-local
|`->no cache found @00.00500s +00.00000s
|`->found local data from DataSourceNoCloud @00.00900s +00.04800s
Finished stage: (init-local) 00.32400 seconds

Starting stage: init-network
|`->restored from cache with run check: DataSourceNoCloud [seed=/var/lib/cloud/seed/nocloud-net][dsmode=net] @01.09400s +00.00200s
|`->setting up datasource @01.13900s +00.00000s
|`->reading and applying user-data @01.14700s +00.00500s
|`->reading and applying vendor-data @01.15200s +00.00400s
|`->reading and applying vendor-data2 @01.15600s +00.00100s
|`->activating datasource @01.18200s +00.00100s
|`->config-migrator ran successfully @01.19400s +00.00000s
|`->config-seed_random ran successfully @01.19400s +00.00100s
|`->config-bootcmd ran successfully @01.19500s +00.00000s
|`->config-write-files ran successfully @01.19600s +00.00000s
|`->config-growpart ran successfully @01.19700s +00.00400s
|`->config-resizefs ran successfully @01.20100s +00.02300s
|`->config-disk_setup ran successfully @01.22400s +00.00100s
|`->config-mounts ran successfully @01.22500s +00.00100s
|`->config-set_hostname ran successfully @01.22700s +00.00100s
|`->config-update_hostname ran successfully @01.22800s +00.00100s
|`->config-update_etc_hosts ran successfully @01.22900s +00.00000s
|`->config-ca-certs ran successfully @01.23000s +00.00000s
|`->config-rsyslog ran successfully @01.23000s +00.00100s
|`->config-users-groups ran successfully @01.23100s +00.04300s
|`->config-ssh ran successfully @01.27500s +00.13200s
Finished stage: (init-network) 00.34000 seconds

Starting stage: modules-config
|`->config-emit_upstart ran successfully @01.79000s +00.00000s
|`->config-snap ran successfully @01.79000s +00.00100s
|`->config-ssh-import-id ran successfully @01.79100s +00.00100s
|`->config-locale ran successfully @01.79200s +01.51700s
|`->config-set-passwords ran successfully @03.31000s +00.00100s
|`->config-grub-dpkg ran successfully @03.31100s +00.09800s
|`->config-apt-pipelining ran successfully @03.41000s +00.00100s
|`->config-apt-configure ran successfully @03.41100s +00.06600s
|`->config-ubuntu-advantage ran successfully @03.47700s +00.00100s
|`->config-ntp ran successfully @03.47800s +00.00100s
|`->config-timezone ran successfully @03.47900s +00.00100s
|`->config-disable-ec2-metadata ran successfully @03.48100s +00.00000s
|`->config-runcmd ran successfully @03.48100s +00.00100s
|`->config-byobu ran successfully @03.48200s +00.00100s
Finished stage: (modules-config) 01.70500 seconds

Starting stage: modules-final
Starting stage: modules-final/config-package-update-upgrade-install
Total Time: 2.36900 seconds

1 boot records analyzed
root@ansible-test-ansible:~# 

The identical launch command-line works fine with centos/8/cloud allowing ssh login. with the ubuntu/focal/cloud image, ssh fails

#from my host workstation
% lxc ls -c n4s $c1                      
+----------------------+-----------------------+---------+
|         NAME         |         IPV4          |  STATE  |
+----------------------+-----------------------+---------+
| ansible-test-ansible | 10.232.221.32 (eth0) | RUNNING |
+----------------------+-----------------------+---------+

ssh -v -i ~/.ssh/ansible 10.232.221.32                              
OpenSSH_8.2p1 Ubuntu-4ubuntu0.2, OpenSSL 1.1.1f  31 Mar 2020
debug1: Reading configuration data /home/peterg/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files
debug1: /etc/ssh/ssh_config line 21: Applying options for *
debug1: Connecting to 10.232.221.32 [10.232.221.32] port 22.
debug1: connect to address 10.232.221.32 port 22: Connection refused
ssh: connect to host 10.232.221.32 port 22: Connection refused
% lxc exec $c1 -- su --login lnxcfg
lnxcfg@ansible-test-ansible:~$ ls -lah .ssh
total 11K
drwx------ 2 lnxcfg lnxcfg  3 Jun 28 18:48 .
drwxr-xr-x 3 lnxcfg lnxcfg  6 Jun 28 18:48 ..
-rw------- 1 lnxcfg lnxcfg 23 Jun 28 18:48 authorized_keys

I struggle to find a single, simple, clear example of how to add the most basic ssh-enabled administrative user in a reasonably platform-independent way. The cloud-init documentation has a pile of IMHO unstructured and elaborate examples, which do not help.

It appears to me to be a very fundamental use-case.

Advice please - have I missed something simple? thanks…

I suspect the reason is as simple as the image not including openssh-server, try to have cloud-init install it for you and see if that resolves it.

Thanks for your time @stgraber.
Indeed the openssh-server package was missing.

Let me show some reasons for my confusion as a dilettante:

Containers launched from: images:/ubuntu/focal allow me to add an ssh-key to the default-user ubuntu, and then to login thus:

% ssh -i /home/peterg/.ssh/ansible ubuntu@ssh1.lxd

No need to add openssh-server. I can also do a whole lot of cloud-init stuff, but I can’t successfully add a new sudo user, using the same profile.

If I use images:/ubuntu/focal/cloud and install the packages openssh-server, and cloud-init, I can now create a new sudo user.

Is there a simple explanation why I fail to add a sudo user to images:/ubuntu/focal?

Cheers…

images:ubuntu/focal does not contain cloud-init, so it will ignore any cloud-init metadata you may be passing. That’s what the /cloud images add.

I have it sorted thanks. I need to learn to check image origins more effectively

lxc image list 'images:ubuntu/focal/cloud' seems to do the trick.

Don’t forget to allow settling time for the configuration to end processing, before you wonder why you cant see the installed packages :slight_smile: