Git, SSH, PuTTY, GitHub, Unfuddle, the kitchen sink

After reading a good number of the guides for getting Git/ GitHub/ Unfuddle working correctly in Windows, I finally got it sorted out. I had to use a bunch of things I had not used before so I realized it's probably a good idea to share my findings, hoping to help someone else (and maybe myself again) in the future.

Local git is easier

Getting Git to run locally in Windows is not hard. It gets a little trickier when you want to work with remote repositories. Especially if, like me, you have little or no experience using SSH in Windows.

In this post I'll install and configure the tools that enable Git to work with remote repositories (e.g. post changes to a server), which I think is probably what a lot of people will want to do, even if you're just toying with Git or evaluating it.

You will need SSH for serious Gitting

The way Git will authenticate and communicate with hosted repositories like GitHub or Unfuddle is through an SSH tunnel. That means we will need an SSH client to connect to the server and Git will use that connection to securely transfer the repository data up and down.

In Linux or on the Mac, SSH is a trivial thing. It's just part of the default installation. For whatever reason, Windows does not come with an SSH client, so we need to find ourselves a 3rd party client.

PuTTY, a family of tools

Luckily for us, there's a free and very popular SSH client for Windows, called PuTTY. PuTTY is actually a family of utilities that play together to configure and establish SSH (and Telnet) connections.

From the PuTTY downloads page get the following programs and put somewhere in your hard disk. I like to put these types of things in a c:\tools\bin directory, which is included in my %PATH%.

Create your SSH key pair

The most common way to authenticate your SSH connection with the server is using an RSA key pair. The pair contains a public key and a private key. Typically these keys will be stored in two files — make sure that the private key file is in a directory location that only your user account has rights. I'm gonna keep both files in %USERPROFILE%\SSH (type echo %USERPROFILE% in a command window to see where yours is.)

To create a key pair we will use puttygen.exe. Just click Generate and then Save public key and Save private key. I chose to leave the password blank and trust that my directory security is enough to protect my keys. Let's assume I saved my keys at %USERPROFILE%\SSH\private.ppk and %USERPROFILE%\SSH\public.ppk, respectively.

We're not done with PuTTY yet

Before starting an SSH connection with PuTTY, we need to run Pageant.exe. Pageant is a background process that will handle the authentication requests. We will add our private key(s) in Pageant and it will keep them available for new connections, without the need to retype the password (if you entered one) every single time.

Run Pageant.exe, double click its icon in the notification area, and add your private key file. If you specified a password, it will now prompt you for that.

Phew! We are done with the SSH crap. Now on to Git. Finally.

Git via msysgit

There are a few ways of installing the git client in Windows, including downloading and compiling the source. But guess if I want to go down that route. Instead, let's just press the easy button and use a pre-packaged installer.

msysgit is what you'll want to install. Donwload the latest release from the site. The file name of the full installer, as of this writing, will be named like Git-[version]-preview[yyyymmdd].exe.

Run the installer accepting most of the defaults, with the exception of these two screens below. We want to Run Git from the Windows Command Prompt and Use PLink (PuTTY.)

 

After this we should have a working installation of Git. You should be able to use Git from both the Windows command prompt and from the Git Bash shell.

Register your public key with the remote server

Now we need to tell the server that hosts the remote repository that it should expect and accept SSH connections from our machine. The way we do this is similar in GitHub and Unfuddle. We just need to associate our public key with our account on that site.

For example, in my GitHub account settings there's a section called SSH Public Keys, where we can add all public keys that we own. Don't use the public key straight from your PuTTY public key file, it uses a different format. Instead, open Puttygen again and load the private key. The public key, in the right format, will be shown in the big text box at the top of the window. Copy that entire text and paste in a new key in your GitHub settings, as seen below.

Troubleshooting

After all that you should have all it takes to use Git in Windows. Until I got to this point I came across some problems. Here are some of them.

No supported authentication methods available. I got that error while trying to push changes because I either forgot to run Pageant or to add the right key into it. The full error is below.

C:\myproject>git push origin master
FATAL ERROR: Disconnected: No supported authentication methods available
fatal: The remote end hung up unexpectedly

The server's host key is not cached in the registry. Sometimes when connecting to a remote server for the first time, the PuTYY will output this message after your Git command.

The server's host key is not cached in the registry. You
have no guarantee that the server is the computer you
think it is.
The server's rsa2 key fingerprint is:
ssh-rsa 1024 [fingerprint here]
If you trust this host, enter "y" to add the key to
PuTTY's cache and carry on connecting.
If you want to carry on connecting just once, without
adding the key to the cache, enter "n".
If you do not trust this host, press Return to abandon the
connection.
Store key in cache? (y/n)

The problem is that Git will not read your keyboard input so you can't type "y" (or "n"). You have to CTRL+C out of it.

The fix for this, is to connect to your server initially using plink -agent github.com directly and then you'll be able to press "y" to cache the server's key locally (and not be prompted again in Git.) Enter "git" as the username if prompted. Now we can get back to Git without that prompt.

Now, that was nerdy

By now, if you got this far in this post, you're probably thinking this is too much work just to get a simple Git client working. I think the current situation reflects at least two things: the people behind Git are definitely not Windows users (d'oh, what a surprise) and the toolset is still relatively immature (in terms of polish, not under the hood) compared to Subversion and CVS for example. The existing GUI's are still very raw and young but, given the increasing popularity of Git, I'll be surprised if by the end of this year this problem isn't gone.


Posted 05-06-2009 4:09 AM by sergiopereira

[Advertisement]

Comments

Lee Brandt wrote re: Git, SSH, PuTTY, GitHub, Unfuddle, the kitchen sink
on 05-06-2009 9:01 AM

I just downloaded the Git Extensions from SourceForge, and it nstalled and setup everything else. I'm not sure if you are doing something more than what I am doing, but I am just cloning repos from github. Take a look at sourceforge.net/.../gitextensions .

Hope this helps

~Lee

sergiopereira wrote re: Git, SSH, PuTTY, GitHub, Unfuddle, the kitchen sink
on 05-06-2009 9:20 AM

@Lee, cloning is fine without all the setup if the repository is public (like most in GitHub.) I own a few repositories (in GitHub and Unfuddle) and needed to update them (push).

I haven't tried Git Extensions yet but it seems to just be a GUI (and shell extension,) probably just executing the Git commands on your behalf. That will still require you to have your SSH stuff already working. I'm sure someone will correct me if I'm mistaken.

I'll try it next time I have some cycles to spare.

jbrechtel wrote re: Git, SSH, PuTTY, GitHub, Unfuddle, the kitchen sink
on 05-06-2009 9:26 AM

You might want to note that there's a TortoiseGit project (like TortoiseSVN) for integration into Windows Explorer.

It works really well, I use it with GitHub and Unfuddle.

code.google.com/.../tortoisegit

joshka wrote re: Git, SSH, PuTTY, GitHub, Unfuddle, the kitchen sink
on 05-06-2009 9:38 AM

msysgit comes with an ssh keygen, client and an agent. No need to use putty

the following in your .profile does the same as pageant (allows you to enter your pwd if any once):

SSH_ENV="$HOME/.ssh/environment"

function start_agent {

       echo "Initialising new SSH agent..."

       /usr/bin/ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}"

       echo succeeded

       chmod 600 "${SSH_ENV}"

       . "${SSH_ENV}" > /dev/null

       /usr/bin/ssh-add;

}

# Source SSH settings, if applicable

if [ -f "${SSH_ENV}" ]; then

. "${SSH_ENV}" > /dev/null

#ps ${SSH_AGENT_PID} doesn't work under cywgin

ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || {

       start_agent;

}

else

       start_agent;

fi

sergiopereira wrote re: Git, SSH, PuTTY, GitHub, Unfuddle, the kitchen sink
on 05-06-2009 9:58 AM

@joshka, will that work in the regular command line or just in the Git Bash?

Good information, though.

DotNetKicks.com wrote Git, SSH, PuTTY, GitHub, Unfuddle, the kitchen sink
on 05-06-2009 10:04 AM

You've been kicked (a good thing) - Trackback from DotNetKicks.com

DotNetShoutout wrote Git, SSH, PuTTY, GitHub, Unfuddle, the kitchen sink - Sergio Pereira - Devlicio.us
on 05-06-2009 10:31 AM

Thank you for submitting this cool story - Trackback from DotNetShoutout

joshka wrote re: Git, SSH, PuTTY, GitHub, Unfuddle, the kitchen sink
on 05-06-2009 11:06 AM

That script is a git bash profile script, you could probably do something similar with a regular command line. I just yoinked that script from somewhere else btw without looking into too much how it works.

ssh, ssh-keygen, etc. seem to be installed as executables in c:\program files\git\bin\

I think they're probably openssh, but I could be wrong.

Nik Radford wrote re: Git, SSH, PuTTY, GitHub, Unfuddle, the kitchen sink
on 05-07-2009 7:17 AM

They are indeed SSH, the msysgit installation gives you two options. To use OpenSSH which is included with the installation or PuTTy (which you download yourself).

I found that OpenSSH the easier to get started with. Because once you have the bash open you can follow the linux tutorials to get going.

Desarrollo web en Rosario wrote re: Git, SSH, PuTTY, GitHub, Unfuddle, the kitchen sink
on 06-02-2009 7:04 PM

Thanks man, it really help me a lot.

See ya.

Juanca

Sean Massa wrote re: Git, SSH, PuTTY, GitHub, Unfuddle, the kitchen sink
on 06-11-2009 2:12 AM

This worked perfectly. Thanks for the tutorial.

Chas wrote re: Git, SSH, PuTTY, GitHub, Unfuddle, the kitchen sink
on 07-21-2009 1:15 PM

I followed your instructions completely, yet I still get the following:

Initialized empty Git repository in C:/Documents and Settings/Chas/Dealz/.git/

Permission denied (publickey).

fatal: The remote end hung up unexpectedly

Any ideas?

sergiopereira wrote re: Git, SSH, PuTTY, GitHub, Unfuddle, the kitchen sink
on 07-21-2009 2:15 PM

@Chas,

I can't add much to what is written in the post itself. I'd suggest to double check that the public key that you generated with puttygen has been saved to a file, that file has been added to pageant and the public key has been added to your github account too. Make sure you copy all the text from the public key text box in puttygen and paste it in github.

Arka Roy wrote re: Git, SSH, PuTTY, GitHub, Unfuddle, the kitchen sink
on 09-22-2009 11:53 AM

Thanks Sergio, very helpful guide.

A lot of hoops to jump through but I kind of got it.  Most importantly, it seems to be working, at least for the moment... :)

Alan Baird wrote re: Git, SSH, PuTTY, GitHub, Unfuddle, the kitchen sink
on 10-10-2009 11:02 AM

Sergio -

Many thanks, using your article I was able to put everything together and make my first push to GitHub.  I don't know why the git guides don't mention any of this since this is really their problem.  Maybe I'm missing something, but I didn't ever read anything about running pageant (which was what I wasn't getting).

FYI - if you installed GIT before you knew to select plink.exe in the installer, all you need to do is find the windows environment variable (right click My Computer->select Properties->click the advanced tab-> click the Environment Variables at the bottom) and change the location.

Alan

greatlyfrustrated wrote re: Git, SSH, PuTTY, GitHub, Unfuddle, the kitchen sink
on 10-30-2009 4:04 PM

Thanks very much.

So seriously screwed up, with such trivial muck.

I had a ".ssh" directory, rather than "ssh".

Also, I duplicated the typical "public.ppk" and "private.ppk" files that PuTTYGen makes to id_rsa.pub and id_rsa, respectively.

Not in love with having to have Pagent running.

Also had trouble deciphering:

Pushing to git://github.com/username/project.git

fatal: remote error:

 You can't push to git://github.com/username/project.git

 Use git@github.com:username/project.git

gitbash push -v git@github.com:username/project.git branchname worked.

I suspect changing "Destination Repository" to "Arbitrary Location" of git@github.com:username/project.git is the fix for git gui.

About The CodeBetter.Com Blog Network
CodeBetter.Com FAQ

Our Mission

Advertisers should contact Brendan

Subscribe
Google Reader or Homepage

del.icio.us CodeBetter.com Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl CodeBetter.com Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of Devlicio.us
Red-Gate Tools For SQL and .NET

NDepend

SlickEdit
 
SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
LiteAccounting.Com
DevExpress
Fixx
NHibernate Profiler
Unfuddle
Balsamiq Mockups
Scrumy
JetBrains - ReSharper
Umbraco
NServiceBus
RavenDb
Web Sequence Diagrams
Ducksboard<-- NEW Friend!

 



Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers

 

Community Server (Commercial Edition)