Monday, November 11, 2013

Windows 7, GitLab, Git for Windows and SSH keys

It's been a while, but here's the latest "WTF WTH WHY IS THIS NOT DOCUMENTED!?!?!?" moment.

So you want to push to GitLab over SSH aye?  This should be simple right?  Follow these steps it took me a couple of hours to figure out, and it will be!

  1. I've assumed you've already installed Git for Windows and GitLab somewhere.
  2. cmd
  3. cd {Directory where you've installed Git for Windows}/bin
  4. ssh-keygen -t rsa
    1. When asked for the location to save to, type in ../.ssh/id_rsa
  5. Open {Directory where you've installed Git for Windows/.ssh/id_rsa.pub}
  6. Copy the contents and set this up as your public key in Gitlab.
  7. ssh git@gitlabserver.
    1. Type y and Enter to add to known hosts.
  8. Close your cmd window.
  9. Edit your environment variables.  If you want to use TortoiseGit you're officially f*cked. 
  10. If there's an environment variable to do with TortoiseGit, delete it.
  11. Edit the global PATH. 
  12. There will be a path that points to {Directory where you've installed Git for Windows/cmd}.  Change this to {Directory where you've installed Git for Windows/bin}.
  13. Just for kicks, copy your .ssh folder to {Drive where you installed Git for Windows}/.ssh and C:\Users\youruser\.ssh.
  14. Hey presto, it should now work!  Use cmd to do your git stuff.
Enjoy.

6 comments:

  1. In case anyone else finds this, it is easier than this to do but GitLab's documentation is shite.

    Follow the doc here https://help.github.com/articles/generating-ssh-keys/

    You don't need to start or add your key to the ssh agent.

    I found testing ssh didn't work but clone worked fine after this.

    ReplyDelete
    Replies
    1. I've just gotten a new laptop so I'll try this out next week thanks!

      Delete
  2. Not sure where my first comment went... the directory ../..ssh/id_rsa doesn't work - we ended up creating an ssh directory under GIT and using ../ssh/id_rsa - and that requires an administrator version of the DOS box... then the command ssh@gitlabserver does zilch. It says "could not resolve hostname gitlabserver: no address associated with name". Can't get past this point...

    ReplyDelete
    Replies
    1. Did you try "../.ssh/id_rsa"? The error you're getting sounds like a DNS issue, what happens if you type "nslookup gitlabserver"?

      Delete
  3. Oooh update. You'll need to set a home environment variable HOME=C:\Users\{your user name}

    ReplyDelete