Setting up your Git SSH Keys to work with CodeSpaces

Posted by Floyd Price on December 17, 2011

Creating a Repository

Creating a repository is as simple as clicking the “New Git Repository” button in the admin section toolbar. Once you have selected a name, etc.. you can click save and the repository will be created in Code Spaces (it can take a minute to create the Git repo on our servers).

Permissions

Git access permissions are setup in the repository settings, and you have a few options:

Basic Mode

Basic permissions mode will gave every user who is a member of the repositories linked projects full R/W access to the repository. This is great for quickly getting a project going where all members are going to need full access.

Advanced Mode

Advanced mode is more granular then Basic mode and requires that you explicitly set permissions for each user who will have access to the repository, you can also set up path based permissions in this view, but the most basic advanced permissions is to give “A User”  ”R/W” access to the path “/”.

 

SSH Keys

No matter what permissions mode you use you wont get access to your Git repository until you set up a SSH key. The following instructions are specific to Mac OSX users but are almost identical to Linux, and Windows instructions are just as easy (here is a great Windows specific write up).

Creating a key for use with Code Spaces

In your favorite terminal go to your .ssh folder and run the ssh-keygen command:

So running the ssh-keygen command will first ask you for a name, i used codespaces_ssh_key in this example but it really doesn’t matter what you call it (its good to use a descriptive name though). Secondly is prompted for a passphrase, i did enter one and simple hit the return key (for a blank passphrase) again this is personal preference but adding a passphrase of your choice here is up to you. (NOTE: this is not your CS password).

And thats it, if you look at the files in your ~/.ssh folder you will now have two new files (codespaces_ssh_key and codespaces_ssh_key.pub in my example).

Uploading your SSH Key to Code Spaces

The file your interested in is the one that ends in .pub so open it up in your editor of choice or just cat it into your terminal output:

Copy the contents of your file as this is what you will be adding to your Code Spaces account to make it all work (pretty geeky ey?)

Open up your Code Spaces account and navigate to your Profile page, you will see a tab names “SSH Keys” and in there you will an area where you can add a key (Key name and key Value). In the Key Value field copy the key from your clipboard and give it a nice name in the Key Name field:

And thats it, once you click the “Add Key” button Code Spaces will associate your key with your account and all the permissions you set up earlier will work.

To clone your repo run the following command:

git clone git@codespaces.com:account_name/repo_name

 

Troubleshooting

 

Unable to Clone Repo (Permission Denied)

If you have setup permissions (either basic or advanced) and have your key uploaded but still get an access denied message you can run the following command from the command line to test your configuration:

ssh -vT git@codespaces.com

This will give you a verbose output and will indicate which key was presented to the server and finally Code Spaces will give you a list of repositories it thinks you have access to.

Can’t push in to a new Repository

The first time you try and push code up to Code Spaces (in an empty repository) you might get an error like:

error: src refspec master does not match any. 
fatal: The remote end hung up unexpectedly

This is normal and can me solved my running the following command

git push origin master

 

 

Leave a comment