Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using CloudInit to automate the startup of my instances on AWS. I followed the (scarce) documentation available at and examples on /usr/share/doc/cloud-init, but still haven't figured out how to change the default username (ubuntu, id:1000).

I know I can create a script to manually delete the default ubuntu and add my user, but seems counter intuitive given that CloudInit exist exactly to automate the initial setup.

Any ideas?

share|improve this question
Will you be building your own AMI or trying to use public AMI? – Skaperen Oct 21 '12 at 2:15
Have you been referring to this document: – Skaperen Oct 21 '12 at 2:17
@Skaperen: I'm using the public Ubuntu 12.04.1 LTS AMI. Yes, I saw the CloudInit docs on, but they don't mention anything about changing the default user. – Gui Ambros Oct 21 '12 at 2:26
up vote 1 down vote accepted

According to this, CloudInit should support custom directives to create new users including overriding the default "ubuntu" user. I've tried it following examples, but haven't been able to get it to work.

However, since CloudInit supports user-data scripts and you can do just about anything in a script, I prefer to use standard commands rather than try to learn some new custom directives.

Here's how I change the default username from "ubuntu" in a user-data script. This example uses the new username "newuser" which you should change to your preference:

#!/bin/bash -ex
usermod  -l $user ubuntu
groupmod -n $user ubuntu
usermod  -d /home/$user -m $user
mv /etc/sudoers.d/90-cloudimg-ubuntu /etc/sudoers.d/90-cloudimg-$user
perl -pi -e "s/ubuntu/$user/g;" /etc/sudoers.d/90-cloudimg-$user

You can add on to this user-data script to do any other initialization and configuration needed on your instances.

Update: I've written an expanded article describing the steps for using both a user-data script and how to do it with CloudInit on recent versions of Ubuntu:

share|improve this answer
Thanks @Eric, that's exactly what I was looking for. And you're right, the more I learn about CloudInit, the more I realize that it's better to just use a standard shell script to customize everything, rather than relying on a new and non-standard syntax of CloudInit. – Gui Ambros Oct 22 '12 at 21:57
I agree with the shell sentiment. One other tip, in addition to doing things in the most straightforward manner do whatever you can to minimize the number of actions scripted during cloud-init. Leave the heavy lifting to a full-fledged CM and make that line between the two as clear as you can. – dmourati Jun 15 '13 at 7:26

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.