Using a new EC2 Instance
Post date: Dec 18, 2010 3:3:47 PM
After launching a new Amazon EC2 Instance, there is a virtual Linux system running. You can make the system more useful by configuring some features.
Prerequisites
Create Amazon Web Services EC2 instance
Login as ec2-user. You may use a different user if you created it.
Update your shell environment
The default command line shell is bash. When you login, the file .bash_profile is run first. You begin in your home directory, which you can always return to by running cd without arguments.
Start by adding LS_COLORS environment variable to your bash profile:
dircolors >> .bash_profile
Edit your .bash_profile:
vi .bash_profile
Change directory name coloring to be cyan instead of dark blue. Where LS_COLORS is assigned, change
di=01;34
to
di=01;36
Configure vim editor
The vim editor is actually used when you run vi. Configure it by creating .vimrc:
vi .vimrc
"Comments begin with quotation mark
"Adjust colors for dark background (use light if needed)
set background=dark
"Remove backwards compatible limitations
set nocompatible
"Turn on indent for new lines
set autoindent
set smartindent
"Status bar at bottom
set ruler
"Highlight matching search strings
set showmatch
"Move cursor as you search
set incsearch
Change "Message of the Day"
The default EC2 message of the day has ASCII art and refers you to read /etc/image-release-notes.
Login as root:
su -
Print the system name and version to the motd file
echo "Welcome to " `uname -n` > /etc/motd
uname -v >> /etc/motd
If you want a custom message, edit the file
vi /etc/motd
Add your local system user to ec2-user authorized users
If you are running Linux or MSYS locally, and have created an SSH keypair before, you can authorize it for login to the EC2 instance. This is an alternative to logging in with the Amazon-generated key-pair.
On your local system:
cd $HOME/.ssh
cat id_rsa.pub
Copy the entire public key.
On the EC2 instance:
vi .ssh/authorized_keys
Append a new line, and paste the public key.
You may now login with your private key using ssh ec2-user@ec2instance.
Use EC2 private key on instance
When you first launched an instance, Amazon generated a private/public key-pair for accessing the instance. The public key was automatically added to the ec2-user authorized_keys file, and the private key was given to you as a .pem file.
Since Amazon has already generated the pair for you, why not use it to identify the instance to outside systems? I'd rather use my own key-pair for my local system, and Amazon's for the EC2 instance.
Upload Amazon's filename.pem file to the .ssh/ subdirectory.
Convert the private key, and regenerate the public key in
cd $HOME/.ssh
openssl rsa -in filename.pem -out id_rsa
chmod 400 id_rsa
ssh-keygen -e -f id_rsa > id_rsa_pem.pub
ssh-keygen -i -f id_rsa_pem.pub > id_rsa.pub
chmod 400 id_rsa*
Access Github repositiories from EC2 instance
Paste the contents of $HOME/.ssh/id_rsa.pub to a permitted key in your github account.
Install git:
sudo yum install git
Clone a repository:
git clone git@github.com:gituser/project.git
Install IRC client
The most popular command line IRC client is IRSSI. It uses the perl shared library, which needs some additional setup in EC2.
sudo yum install irssi
sudo cp -pr /usr/lib64/perl5/CORE/* /usr/local/lib/
sudo ldconfig
irssi
/set user username
/set nick username
/connect irc.freenode.net
/quit
Estimate costs
If you're ready for more resources beyond the free tier, you can estimate the monthly cost using Amazon's calculator:
http://calculator.s3.amazonaws.com/calc5.html
What now?
Software development, HTTPS proxy, stay connected to IRC, seed a file on Bittorrent. Lots of things you can do with a server :)