Skip to content

[docs]: Explicitly mention that setting (and unlocking) passwords for existing users require the chpasswd module not users.[].hashed_passwd|plain_text_passwd + users.[].lock_passwd #6703

@mostafaCamel

Description

@mostafaCamel

Documentation request

The cloud-init examples suggest that using hashed_passwd and lock_passwd for already-exsting users

Here is the excerpt from the documentation

# Add users to the system. Users are added after groups are added.
# Note: Most of these configuration options will not be honored if the user
#       already exists. Following options are the exceptions and they are
#       applicable on already-existing users:
#       - 'plain_text_passwd', 'hashed_passwd', 'lock_passwd', 'sudo',
#         'ssh_authorized_keys', 'ssh_redirect_user'.

So I try the following cloud-init

#cloud-config
users:
  - default
  - name: ubuntu    
    shell: /bin/bash
    hashed_passwd: $6$ViQQI4kReDWrps3y$TSzStkHkxYKn6VlaWRVrhwZSsoVe3nxolR58Iz0063Rp1Ba4w8gFtep9uy4N8cpmcF7Ey0fYrm2lmcYEHT.E./
    lock_passwd: false
    sudo: ALL=(ALL) NOPASSWD:ALL

However, I am unable to loginvia console. When I ssh into it and I run sudo cat /etc/shadow | grep ubuntu , I get ubuntu:!$6$ViQQI4kReDWrps3y$TSzStkHkxYKn6VlaWRVrhwZSsoVe3nxolR58Iz0063Rp1Ba4w8gFtep9uy4N8cpmcF7Ey0fYrm2lmcYEHT.E./:20484:0:99999:7:::
Notice the exclamation mark before the hashed password, which means that we are unable to use this password for login

When I try the following cloud-init, I am able to login via console. Notice that I did not even need to set lock_passwd

users:
  - default
  - name: ubuntu    
    shell: /bin/bash
    sudo: ALL=(ALL) NOPASSWD:ALL
chpasswd:
  expire: false
  users:
  - {name: ubuntu, password: $6$ViQQI4kReDWrps3y$TSzStkHkxYKn6VlaWRVrhwZSsoVe3nxolR58Iz0063Rp1Ba4w8gFtep9uy4N8cpmcF7Ey0fYrm2lmcYEHT.E./}

Image used: https://cloud-images.ubuntu.com/jammy/20251216/jammy-server-cloudimg-amd64.img

ubuntu@vmwithpassword:~$ cloud-init --version
/usr/bin/cloud-init 25.2-0ubuntu1~22.04.1

ubuntu@vmwithpassword:~$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 22.04.5 LTS
Release:	22.04
Codename:	jammy

fwiw, sudo virt-cat -a ubuntu-22.04-server-cloudimg-amd64.img /etc/passwd | grep ubuntu and sudo virt-cat -a ubuntu-22.04-server-cloudimg-amd64.img /etc/shadow | grep ubuntu return nothing, which mean that the image by iitself does not have the user and that the user is created later (early during cloud-init)

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationThis Pull Request changes documentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions