SSH Configuration Files

Lately I have been managing a ton of servers, all using different users, passwords, key’s etc. I wanted an easier way to access them, and a friend pointed out SSH config files. I personally hadn’t used them and there was not really some place to show there use other then great walls of text. I figured I would setup a post to keep track of how I been using them for both myself and anyone else that might be interested.

 

The config file is contained in your .ssh folder located in your home. There are a few directives in the files that I use constantly. Here is an example of a file that I might have setup

 


Host local-server-name

HostName 0.0.0.0

Port 22

User Me

IdentityFile ~/.ssh/local-server-name-key

 

The first value Host is what I want to use as a name for that server locally. Depending on how much typing you like to do you can make it as long or as short as you want. HostName is the ip or address used for connecting to the server normally. The Port only needs to be added if your using a port other then 22. User is the user name that you wish to connect to with. IdentityFile is the location of the private key that you might have setup on that server for authentication.

Once this file has been created and you have all your servers added, you can now access any of these servers via there name in most commands.

 

Connecting to the server via SSH


ssh local-server-name

 

Sending a file to the server


scp ./filename.text local-server-name:/

 

Your configuration file can have as many entries as you want for as many servers as you want. You can even have the same server setup multiple times with different User or User/IdentityFile. I hope this was helpful, I know it has saved me a ton of typing on many occasions.

It’s Been Too Long

It has been some time since my last post, things were getting a little busy for a while. Lots of work to do both for my own projects as well as for clients. In October I started a full time position with a local start up, for now I won’t make mention of what I will be doing or for who I will be doing it for, but its going to be some awesome stuff.

 

My New Years Resolution this year was to do a much better job at maintaining this site, as well as keeping to a sort of floating posting schedule. I will try and maintain at least one post per week, maybe more if I find the time. I want to also start posting reviews on items that I use, enjoy, read or like in hopes that maybe someone else thinking of getting such items will see value in them.

Freeze and Unfreeze Environments

In a previous post I explained how to setup VirtualEnv and start a new project. I however never explained the one important aspect of VirtualEnv. Saving a requirements file, a list of all installed libraries, is one of the must useful aspects. Allowing yourself or other developers to easily load up the environment you used, the same libraries, same versions. All without overwriting your changing the versions your using on your own system, or other projects.

Freezing

Let’s say your sitting in front of a newly created project, you just setup the environment, installed all the foreseeable libraries, setup the structure of your project, and create the repository and committed all your changes. Your missing one thing, a requirements file, a file outlining to yourself or anyone else that might work on your project exactly what libraries you have. Creating such a file really is not that difficult, deciding where you want to put it, that can be tricky. I always place my requirements file right at the root of my repository. To create this file just run the following command, either keep it as is to drop your file in the current working directory, or add a path to it.


pip freeze > requirements

 

You now have your very own requirements file setup specifically for your project. The only task left for you at this point, is to add it to your repository and commit the changes. If down the road you need to install new libraries, running this command and overwriting your file, is perfectly fine, just be sure to commit those changes also.

 

Unfreezing

If you are about to work on an existing project, and have this project checked out and ready to go. The first thing you will want to do is setup the environment for that project, and activate it.


virtualenv --no-site-packages --distribute [project_folder]

cd [project_folder]

source bin/activate

 

Afterwards enter the project folder, assuming the original developer used similar naming conventions and named there requirements file requirements, you can install all the required libraries.


pip install -U -r requirements

 

If the original developer didn’t use any kind of environment, and they just simply listed the requirements. You are still in a good spot, you can build the environment from here using pip to install all the packages you need then saving your own requirements file.

Python and MySQL dev on OSX

One of the biggest pains I have when developing on OSX is always trying to get MySQLdb working. Its one of those things that just doesn’t seem to be easy enough. I prefer not having MySQL running right off my desktop if I can so I will describe how I get MySQLdb running without installing the whole server, on Snow Leopard, using a VirtualEnv, and running 64bit.

 

Step 1

Download the necessary packages


wget http://www.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.13-osx10.6-x86_64.tar.gz/from/http://mysql.mirror.rafal.ca/

wget http://sourceforge.net/projects/mysql-python/files/mysql-python/1.2.3/MySQL-python-1.2.3.tar.gz/download

 

Step 2

Uncompress the archives


tar -zxvf mysql-5.5.13-osx10.6-x86_64.tar.gz

tar -zxvf MySQL-python-1.2.3.tar.gz

 

Step 3

The first thing thats needed to be done is located the exact path of mysql_config, which should be located directly in the bin/ folder of the extracted files from MySQL, for my files they are located in ~/temp/mysql-5.5.13-osx10.6-x86_64/bin/ with this in mind change your working path to the root of your extracted MySQL-python-1.2.3 and modify the site.cfg file so that it now contains a mysql_config


vim site.cfg

mysql_config = ~/temp/mysql-5.5.13-osx10.6-x86_64/bin/mysql_config

 

Step 4

Now its time to build the library while still in the root of your extracted MySQL-python-1.2.3 be sure to run the build


export ARCHFLAGS="-arch i386 -arch x86_64"

python setup.py build

note: I added the export to allow for 64bit compiling under the newer versions of xcode

 

Step 5

Now that the build is complete, you don’t have any use for the extracted version of MySQL server, but we still need the libraries. Enter back into the root of the mysql-5.5.13-osx10.6-x86_64 and lets put them on our systems. Afterwards you can delete the files associated with MySQL Server (mysql-5.5.13-osx10.6-x86_64)


cd ./lib/

cp ./*.dylib /usr/lib/

 

Step 6

From here its up to you, you can install the libraries system wide or you can install them on a per environment bases


source ./bin/activate

cd ~/temp/MySQL-python-1.2.3/

python setup.py install

 

Once you have completed all these simple tasks you will have a system or environment with a mysql connectable python. Also located in the MySQL-python-1.2.3 folder there will now be a dist/ folder which will contain a nicely packaged egg that you can use for future installs on your system. Which makes the whole process easier to install assuming you picked the route of installing on a virtual environment. Save the egg for later and use it again when you need a new install in a new environment.


easy_install MySQL_python-1.2.3-py2.6-macosx-10.6-universal.egg