Git with Attlasian Stash via SSH, on Windows

I do not know why Atlassian decided to name the thing Stash when there was  Git stash, probably some "clever" marketing.

I used Git for some time but just recently I had to use the SSH protocol on Windows  to authenticate to Stash. Integrating Linux-born software to Windows environment is sometimes easy but that was not this case - to prevent more people to curse Git because of that, I made the following HOWTO.

Install Git

First of all you need to install Git and configure access using SSH protocol.  I decided to not try anything fancy and downloaded the standard git client installation file. There is several dialogs during installation, I recommend to use "Run Git from Windows Command Prompt" in the "Adjusting PATH Environment"second dialog. The most important option is "Choosing SSH executable" - select "Use OpenSSH" - the Git will then use OpenSSH included in GIT installation.

I installed Git into directory C:\git, feel free to choose installation path that suites your needs. I would recommend to avoid using path wit space though.

When finished, open powershell console and go to directory to C:\git\bin.

Generate SSH Keys 

Following command generates new pair of keys (private will stay with you and public will be given later to Stash for you authentication).

C:\git\bin> .\ssh-keygen.exe -t rsa -C your.email@address.com

Set basic key file name to C:\git\bin\id_rsa when asked for the keys. To make things simple, use empty pass-phrase (you can fortify your setup later when you get more familiar with OpenSSH). The conversation with ssh-keygen should look like this:

Generating public/private rsa key pair.
Enter file in which to save the key (//.ssh/id_rsa): C:\git\bin\id_rsa
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in C:\git\bin\id_rsa.
Your public key has been saved in C:\git\bin\id_rsa.pub.

Configure Bundled OpenSSH

Create directory C:\git\.ssh and move the newly created files id_rsa (private key) and id_rsa.pub (public key) into it. Then create file C:\git\.ssh\config with following content:

Host stash.atlassian.com
    HostName stash.atlassian.com
    PreferredAuthentications publickey
    IdentityFile /.ssh/id_rsa

In case your company has its own Stash instance running, adapt the Host and HostName options accordingly.

Submit Public Key to Stash

Login to your Stash account.  In the top right corner, from select from drop-down menu "Manage account".  On left side of the page you should now see several links, click on "SSH Keys".

Put content of your public key (id_rsa.pub) into the text of the provided form. Do not edit it the content at all. Removing, regardless if deliberate or accidental, of some  white space characters, namely line breaks does not prevent Stash to accept the key but the authentication will fail.

Test Connection

First test the connection using only OpenSSH:

C:\git\bin> .\ssh.exe -v -T git@stash.atlassian.com -p 7999

If everything works well, the output you get ends with sentences "Authentication succeeded." and probably also "Entering interactive session." If so, you can move C:\git\bin\.ssh directory to C:\your_windows_login\ directory and retest that the connection still gets authenticated with the files in new location:

C:\git\bin\ssh.exe -v -T git@stash.atlassian.com -p 7999


If everything worked as described so far you should be now able clone your Stash-hosted repository using instructions available from Stash profile or project page.