Ask Your Question

How can I create a user on ubuntu VM via cloud init?

asked 2016-05-03 15:10:35 -0500

jafar gravatar image

updated 2016-05-04 09:11:30 -0500

I'm able to ssh into my Ubuntu VMs and modify some things via cloud init, such as adding proxies and installing packages, but I'd like to create users with cloud init. However, if I try to create a user with cloud init and then ssh in, my key is rejected. I've tried to include the key into the cloud config as below:

  - name: newuser
       - <key>
    sudo: ['ALL=(ALL) NOPASSWD:ALL']
    groups: sudo
    shell: /bin/bash

This allows me to ssh into the machine but then the user is not actually created (at least, it is not in /etc/passwd). What am I doing wrong?

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted

answered 2016-05-19 11:15:35 -0500

rmelton gravatar image

updated 2016-05-19 12:25:21 -0500

possibly break this into 2 problems:

1. make sure you can reliably get the new user created and you can see it in passwd file and home dir is created.
Here's what works for me with Ubuntu 14.04 VM :
        - default
        - name: user01
          lock-passwd: false
          passwd: 's0oC/Amo1kHG6' 
          shell: /bin/bash
          sudo: "ALL=(ALL) NOPASSWD:ALL"
        ssh_pwauth: true
if you don't want the default user or pwauth, then remove those parts.

2. after new user is created in VM, get PKI working.
Pass the nova keypair name when createing the VM:
type: "OS::Nova::Server"
      name: my_vm
      image: { get_param: image }
      flavor: { get_param: flavor }
      key_name: { get_param: key_name }

When you attempt 'ssh -i privatekey.pem user@' make sure you're using a private key which was created with the public keyname which you passed to ::Server in the template above. Make sure that PKI is enabled in /etc/ssh. If you can get into VM (possibly thru horizon instance console login), watch /var/log/auth.log to see what happens when you attemp ssh from outside.

edit flag offensive delete link more

answered 2016-05-04 04:55:56 -0500

yprokule gravatar image

updated 2016-05-04 04:57:21 -0500

Here is snippet I'm using for user creation:

  - name: admin
    groups: wheel
    lock-passwd: false
    passwd: $6$8clcR2yc$mRhXO8AZIgphwWhzyYzdqa39IMgxy4udN9zmSHdJH6Xfz19Z1qBYFqgV.5eFbod5VK3Izy/ytr4qPXJNLWzl00
      - ssh-rsa A...

Base on your snippet U ain't passing ssh-key as list though, I'm not sure

edit flag offensive delete link more


Double checked and I just formatted my question wrong, my key is in list form in the input file. Tried again just to be safe and though I can ssh in, the new user still doesn't show up.

jafar gravatar imagejafar ( 2016-05-04 09:11:51 -0500 )edit

@jafar - I'm confused, U can ssh like ssh -i key newuser@vm ? what is your home dir? try running getent passwd newuser

yprokule gravatar imageyprokule ( 2016-05-10 04:01:53 -0500 )edit

this guy is working with ubuntu VM. ubuntu doesn't have wheel group does it?

rmelton gravatar imagermelton ( 2016-05-19 11:03:10 -0500 )edit

@rmelton, not sure if it exists in ubuntu, though it exists in rhel :) And that snippet from my cloud-init that works for me :)

yprokule gravatar imageyprokule ( 2016-05-19 23:21:46 -0500 )edit

Get to know Ask OpenStack

Resources for moderators

Question Tools



Asked: 2016-05-03 15:10:35 -0500

Seen: 3,496 times

Last updated: May 19 '16