I'm using CloudInit to automate the startup of my instances on AWS. I followed the (scarce) documentation available at http://bazaar.launchpad.net/~cloud-init-dev/cloud-init/trunk/annotate/head%3A/doc/examples/cloud-config.txt 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?

  • Will you be building your own AMI or trying to use public AMI?
    – Skaperen
    Oct 21, 2012 at 2:15
  • Have you been referring to this document: help.ubuntu.com/community/CloudInit
    – Skaperen
    Oct 21, 2012 at 2:17
  • @Skaperen: I'm using the public Ubuntu 12.04.1 LTS AMI. Yes, I saw the CloudInit docs on ubuntu.com, but they don't mention anything about changing the default user.
    – Gui Ambros
    Oct 21, 2012 at 2:26

2 Answers 2


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: http://alestic.com/2014/01/ec2-change-username

  • 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, 2012 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, 2013 at 7:26

You can put this in userdata:

    name: otherusername
  • 2
    Just a note that #cloud-config is important at the start of file in order to work Nov 5, 2023 at 23:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .