For this example I will be using an EBS backed AMI in the
east-1 region. This AMIs id is ami-7539b41c

Cloud-init

AWS allows you to pass in script as a file or text when
instantiating a server. This script will
then be run during the creation process.
You can for example send it a bash script and it will execute it just
fine.

However, rather than using bash, there is new script language in town
cloud-init https://help.ubuntu.com/community/CloudInit [2]
One part of this is the cloud-config script. This idea is still in development, but it
works well now, I believe their goal is
to have a script more focused on “what would you do on initialization” . Focusing more on things like adding
users, getting ssh keys set up etc.

I am not going to go into great depth on how to use cloud
init, I am mostly just going to show you a script that works and explain that
script a little. To see more examples
you can go to the /usr/share/doc/cloud-init/examples folder on your ubuntu
install and read the examples there.

Here is the cloud-config script I came up with to help
create a git server in the AWS cloud.
(replace the ssh keys and password with your own

#cloud-config

#

# This cloud-config file
creates a git server

#

apt_update: true

apt_upgrade: true

#

# Add the git package

#

packages:

- git-core

# Add groups to the system

# The following example adds
the ubuntu group with members foo and bar and

# the group cloud-users.

groups:

- git

- patman

# Add users to the system.
Users are added after groups are added.

users:

- default

- name: git

shell: /usr/bin/git-shell

gecos: git user

primary-group: git

lock-passwd: true

ssh-import-id: None

#

# Add SSh keys for every
user of the git repository

#

ssh-authorized-keys:

- ssh-rsa AAAAB3NzXXXX

- ssh-rsa AAAAB3NzXXXX

#

# This is not
"needed" I am just adding myself to the system as a user who can
ssh into the box

#

- name: patman

shell: /bin/bash

gecos: Patrick Bailey

primary-group: patman

groups: admin

passwd: $6$aFXXXXXX

ssh-import-id: None

ssh-authorized-keys:

- ssh-rsa AAAABXXXX

- ssh-rsa AAAABXXXX

#

# This is a work around to a
but

# The users password is
locked upon creation and should not be

# This just unlocks it

#

runcmd:

- [passwd, patman, '-u']

This script

·installs the git tool

·Create the git user

·Sets the git default shell to usr/bin/git-shell,
this will allow git programs to work via ssh but not allow a shell to ssh into
for users.

·Puts all the public SSH keys into the gits
aurhorized_keys file

·Create the user “patman” with ssh access and a
set password for the machine (the password is the encrypted password as seen in
/etc/shadow

Save this file off as a script called

cloud-config-git.txt

Create the EC2 machine

The following assumes you have installed and are familiar
with the AWS command line tools and have them installed on their system.

In case you need to edit this you can remove the origin by
running the command “git remote rm
origin” Oh, and origin is not a special
name you could use bob instead if you like, or whatever makes sense for you.

Before uploading this repository to the git server you can
check to see if anything needs to be checked in

> git
status

Now push this project up to the master

> git
push origin master

Success!

Now for some testing

I will try a few different test setups to download from this
master server and to upload to it.

Command line: clone the master
repository

From your local machine, in another directory run the
following commands.