Sunday, March 13, 2011

Getting Started With Open States -- Fun with GitHub and Public Keys

A couple months back I started to hear about a great project called Open States whose goal is to scrape data from web sites of each state within the union so that the information could be shared more easily. I really wanted to get involved with this project but there were a couple issues:
  1. Project used python (don't know it)
  2. Project hosted on GitHub (haven't used it)
  3. All of the supporting documentation was for linux users (I can use Linux as a general office worker... using it as a development platform is beyond me at the moment)
Even with all of those issues I still wanted to get involved so I read a couple books on python programming,  reviewed the code base, and tried to figure out what it meant to be a Git user along with doing development on Linux.  I started off with their Contribution Guide and read the getting Getting Started on GitHub.  Then I tried to get my environment setup.  After installing Git and the python dependencies pointed out in the Contribution Guide I tried to clone my forked version of the openstates repository and that is where the fun began.

I was supposed to be able to run the following command from the shell in order to get the code downloaded to my computer.

git clone git@github.com:jwmajors81/openstates.git

However, I ran into two issues.

  1. My account within Linux didn't have permission to update the known_hosts file (/home/jeremy/.ssh/known_hosts
  2. I got a permission denied message from GitHub... the exact message was "Permission denied (publickey)"

After looking at the SSH Troubleshooting guide on GitHub I realized that I skipped a couple steps in my setup.... however fixing that issue was a little harder than I would have wished. I ended up resolving the issue by running all git and ssh commands using SUDO. I know that isn't the most ideal way to do this, but I just couldn't figure out how to give my user id (jeremy) access to the /home/jeremy/.ssh/ directory. I'm sure if I would have looked into it more I would have found the solution (chmod is your friend), but I simply didn't want to deal with it at the moment. So I did the following:

  1. Executed sudo ssh-keygen -t rsa "{email address}" and at all of the prompts I just hit enter to accept defaults. This populated the /root/.ssh/id_rsa.pub file with a key
  2. Copied key generated in id_rsa.pub file to Account Settings in GitHub. Look at step 4 on http://help.github.com/linux-set-up-git/ for more information
  3. Executed sudo ssh git@github.com to make sure that everything was setup. If you get permission denied then that means that you didn't do something correctly :(
    1. you can use the command sudo ssh -v git@github.com to get more verbose messages about the failure. If you don't see "Offering public key: /root/.ssh/id_rsa" in the debug messages then that means you don't have any public keys ready to offer.

At that point I was able to execute sudo git clone git@github.com:jwmajors81/openstates.git and finally the forked code was on my machine. Time for a beer.

No comments:

Post a Comment