How to generate SSH keys for Git authorization

Featured Image

Some rights reserved by @boetter / flickr

Hi there! This post will be pretty straightforward and will cover Windows, Mac and Linux, so if you don’t know how to do it already, read on.

Head 1: Windows

Just follow these 5 steps:

  1. Go to this address, and download msysgit, after the download install it with default settings
  2. Open Git Bash that you just installed (Start->All Programs->Git->Git Bash)
  3. Type in the following: ssh-keygen -t rsa (when prompted, enter password, key name can stay the same)
  4. Open file your_home_directory/.ssh/id_rsa.pub with your favorite text editor, and copy contents to your Git repository’s keys field (GitHubbeanstalk, or any other repository provider), under your account.
  5. Be sure that you don’t copy any whitespace while copying public key’s content (id_rsa.pub)

Note: your_home_directory is either C:\Users\your_username (on Windows Vista / 7), or C:\Documents and Settings\your_username (on Windows XP)

Head 2: Mac

Follow these 5 steps:

  1. Start the terminal
  2. Navigate to your home directory by typing: cd ~/
  3. Execute the following command: ssh-keygen -t rsa (when prompted, enter password, key name can stay the same)
  4. open file you’ve just created ~/.ssh/id_rsa.pub with your favorite text editor, and copy contents to your Git repository’s keys field (GitHub, beanstalk, or any other repository provider), under your account.
  5. Be sure that you don’t copy any whitespace while copying public key’s content (id_rsa.pub)

Head 3: Linux (Ubuntu)

Follow these 5 steps:

  1. Open console
  2. cd ~
  3. ssh-keygen -t rsa (when prompted, enter password, key name can stay the same)
  4. open file /home/your_username/.ssh/id_rsa.pub with your favorite text editor, and copy contents to your Git repository’s keys field (GitHub, beanstalk, or any other repository provider), under your account.
  5. Be sure that you don’t copy any whitespace while copying public key’s content (id_rsa.pub)

Head 4: Additional info

When you create private / public SSH keys on your machine (that’s what you did in above steps), it’s not enough. You need to give your public key to the repository in order to pair the Git server with your local machine (that’d be steps 4. and 5. above).

Most of the popular repositories will give you web interface access to the application, and here’s how it looks like on beanstalk when you did all you needed, for example:

After this step, you’re ready to start using Git.

Head 5: Conclusion

I hope this wasn’t to complicated to follow, and also I hope it was helpful to someone!

Cheers!

6
Top

Care to rate this post?

Author

Mladen Lotar

Ex. Inchooer

Mladen worked at Inchoo from 2010 to 2011 in the role of Magento/Zend developer

Other posts from this author

Discussion 6 Comments

Add Comment
  1. Max

    I have created a key that I use to connect to a git repos. When I commit, my username and domain (memine@myMachineName123.local) shows up as who committed the change. I dont want that, but instead it to show my Alias or other name.
    Is there a way to change this in the key generation so that when i upload my key, my commits show as by ‘Alias’ or something else?

    Thanks.

  2. Mark

    For anyone following this tutorial, if you’re having problems finding your rsa file, note that before you open Git Bash you need to set the HOME environment variable to point to your folder of choice. then, when you run the keygen it will put it in a sub-folder .ssh underneath the the folder defined in your HOME env variable.

    see Answer#1 at http://stackoverflow.com/questions/6723912/establishing-a-github-ssh-connection-is-this-the-right-way

  3. Tom

    Really useful thanks for the post.

  4. Thanks a lot, good stuff. It saved me some time

    @Max
    add comment with -C option, while generating your keys

  5. bob

    why are you blurring out a public ssh key?
    It’s not a secret it’s your public key, they’re nothing blurring it would help with.

  6. Cool photo of the green bench! :)

Add Your Comment

Please wrap all source codes with [code][/code] tags.
Top