Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Amazon Linux 2 first boot on Virtual Box
# Download the VDI from
# Doc is at
# Be sure you have config/meta-data and config/user-data ready as per the below
# change ec2-user's password to your password
$ cat config/meta-data
local-hostname: amazonlinux.onprem
# eth0 is the default network interface enabled in the image. You can configure
# static network settings with an entry like below.
#network-interfaces: |
# iface eth0 inet static
# address
# network
# netmask
# broadcast
# gateway
$ cat config/user-data
# vim:syntax=yaml
# A user by the name ec2-user is created in the image by default.
- default
# Following entry create user1 and assigns password specified in plain text.
# Please not use of plain text password is not recommended from security best
# practises standpoint
# - name: user1
# groups: sudo
# sudo: ['ALL=(ALL) NOPASSWD:ALL']
# plain_text_passwd: < plain text password here >
# lock_passwd: false
# Following entry creates user2 and attaches a hashed passwd to the user. Hashed
# passwords can be generated with:
# python -c 'import crypt,getpass; print crypt.crypt(getpass.getpass())'
# - name: user2
# passwd: < hashed password here >
# lock_passwd: false
# Following entry creates user3, disables password based login and enables an SSH public key
# - name: user3
# ssh-authorized-keys:
# - < ssh public key here >
# lock_passwd: true
list: |
# On Mac OS, you can use hdiutil instead of genisoimage
hdiutil makehybrid -o init.iso -hfs -joliet -iso -default-volume-name cidata config
## Then attach the init.iso file to the virtual machine before to boot the VDI.
## Cloud-init configuration happens ar first boot only, you do not need the ISO file for subsequent boots
## If you need to retry, re-try from the originally downloaded VDI
## Keep a copy of the downloaded VDI if you need to make changes to your root disk image.

This comment has been minimized.

Copy link

dwhite-beerhawk commented Apr 30, 2018

Could you expand on this gist a little? I've been following the docs and such examples - but cannot log into the VM. I get a "Login incorrect" for all users.
The .vdi I've set as the SATA drive in Vbox and I've mounted the init.iso as the IDE.


This comment has been minimized.

Copy link

jonathan-automox commented Jul 2, 2018

Yeah, I couldn't get it to work either same setup as dwhite-beehawk.


This comment has been minimized.

Copy link

sdbruder commented Jul 27, 2018

I can login locally (on the terminal) but not via ssh because of 2 things:
as described the eth0 does not go up, there is no ONBOOT=yes in eth0 config.
and sshd is denying any by password login.

So after manually fixing these issues up Ive being able to login.

As configured eth0 will be directly in your network, bridged, not on the NAT’ed VMware Fusion network.

So if someone has some more information on how we can get ONBOOT=yes for eth0 on meta-data, that password thing can be avoided configuring a key for the user.


This comment has been minimized.

Copy link

cuoituoi1996 commented Jul 27, 2018

i also have the same issue where it said "login incorrect". Could you elaborate on what you did to be able to log in @sdbruder?


This comment has been minimized.

Copy link

AndrewStringerJS commented Aug 15, 2018

I had this issue too, the solution (for me) was to validate the files used to create the seed.iso file, this worked for me:- and found an error.

# vim:syntax=yaml
# A user by the name ec2-user is created in the image by default.
- default

In the last line, the default statement needed two spaces in front of it, then it validated ok, the rebuild seed.iso then seemed to do the trick and I could log in as ec2-user with my password.

Remember to use a fresh .vdi file as the seed.iso is only valid on first boot and booting touches the vdi image so it cannot be used again. You may be able to do a snapshot before the initial boot too to preserver the initial state. But I have not tried this.


This comment has been minimized.

Copy link

omenking commented Sep 6, 2018

I noticed during boot on mine it thought the seed is not valid

screen shot 2018-09-06 at 10 16 46 am

I built it on osx
hdiutil makehybrid -o seed.iso -hfs -joliet -iso -default-volume-name cidata seedconfig/

I did validate my yaml

Reading through here:

I think its something to do with my seed.iso, it is mounted in VirtualBox


This comment has been minimized.

Copy link

davidkaufman commented Oct 16, 2018

Thanks for the suggestions!

In my case, it turned out that my "incrorrect login" errors were fixed by removing a COMMENT line that i had added above the first line of the user-data file. So my file started with:

# my comment here ( a URL to the docs), then...


Although it was still syntactically correct yaml, it didn't actually work until i removed that top/first comment that i'd added...

So there is, apparently, an undocumented requirement that the file MUST BEGIN WITH with the #cloud-config comment...


Still not sure if the vim:syntax comment is required too but I'm leaving it, cuz I've lost enough time to this nonsense already :-)

Thanks again for your suggestions, which led me to to my discovery and the fix for my situation!

Hope this helps someone googling this issue like i did!



This comment has been minimized.


This comment has been minimized.

Copy link

jrblakely commented Aug 10, 2019

I doubt anyone is as lame as I am, but I created the text files using NOTEPAD under Windows Cygwin, and I am pretty sure the non-standard line terminators did bad things.

I deleted the NOTEPAD files and recreated using vi and everything worked as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.