Ask Your Question
0

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:

users:
  - name: newuser
    ssh-authorized-keys: 
       - <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
0

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:

users:
  - name: admin
    groups: wheel
    lock-passwd: false
    passwd: $6$8clcR2yc$mRhXO8AZIgphwWhzyYzdqa39IMgxy4udN9zmSHdJH6Xfz19Z1qBYFqgV.5eFbod5VK3Izy/ytr4qPXJNLWzl00
    ssh-authorized-keys:
      - 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

Comments

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
0

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 :
        users:
        - default
        - name: user01
          groups: 
          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"
    properties:
      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@0.1.2.3' 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

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Get to know Ask OpenStack

Resources for moderators

Question Tools

2 followers

Stats

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

Seen: 2,046 times

Last updated: May 19 '16