Managing linux EC2 instances (or any remote linux machines)


Its been a while since I posted anything so I thought I would talk about how I've setup my servers using Amazon's EC2 cloud services for easy administration. I have several instances running mostly Ubuntu 10.04.

Some of this stuff may be pretty simple to you depending on your level of expertise but it really simplifies administration for me so I wanted to share.

I put all my keys in a folder in my home directory and then I have a file named config in my ~/.ssh folder that looks something like this:

Host server_alias
User ubuntu
Hostname public_address_to_server
IdentityFile ~/.keys/key_file.pem
Localforward 6033 localhost:3306

I have an entry like what is shown above for each server. Once you have a host setup in your config file, you can ssh to your server with one very simple command:

ssh server_alias

Wow, that was easy. There's also a bunch of other cool things you can do once you have this setup.

You'll notice I have a local forward setup on port 6033. This allows me to connect to my remote MySQL server (running on its default port of 3306) once I have established an SSH connection using the port 6033. I can use MySQL GUI tools or simply connect with the MySQL command line utility like so:

mysql -h -P 6033 -p

I am not sure why but for whatever reason, it doesn't work if I enter localhost but if I use it does. Weird.

File sharing over ssh is also pretty simple. Simply use the sshfs command line tool:

sshfs server_alias:/home/whatever_dir ~/server_alias

Booyah, now I can manipulate folders and files on my remote server locally. If you want to kill the share, simply use:

fusermount -uz server_alias

Happy server administrating!