How to generate SSH keys for Git authorization

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.
Windows
Just follow these 5 steps:
- Go to this address, and download Git for Windows, after the download install it with default settings
- Open Git Bash that you just installed (Start->All Programs->Git->Git Bash)
- Type in the following: ssh-keygen -t rsa (when prompted, enter password, key name can stay the same)
- Open file your_home_directory/.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.
- 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 / 8 / 10), or C:\Documents and Settings\your_username (on Windows XP)
Mac
Follow these 5 steps:
- Start the terminal
- Navigate to your home directory by typing: cd ~/
- Execute the following command: ssh-keygen -t rsa (when prompted, enter password, key name can stay the same)
- Open the 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.
- Be sure that you don’t copy any whitespace while copying public key’s content (id_rsa.pub)
Linux (Ubuntu)
Follow these 5 steps:
- Open console
- cd ~
- ssh-keygen -t rsa (when prompted, enter password, key name can stay the same)
- 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.
- Be sure that you don’t copy any whitespace while copying public key’s content (id_rsa.pub)
Additional info
When you create private/public SSH keys on your machine (that’s what you did in the 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 Github:
After this step, you’re ready to start using Git.
Conclusion
I hope this wasn’t too complicated to follow, and also I hope it was helpful to someone!
Cheers!
____________________________________________________________________________________________
Note! This article was revised on Jul 26, 2019. The original article was posted in 2011 by Mladen Lotar.
18 comments
Thanks a lot, it works
Thanks! Easy and works (for me at least)!
Informative post Hrvoje.Thanks
Short and crisp. Worked for me for Windows 10.
how did you get Win10 to create the .ssh dir? Neither Git Bash nor myself can create said directory. Even though the shell reports back having stored the key in /u//.ssh/id_rsa. That directory does not exist. Also, neither of the rsa files show anywhere on my machine. I conducted several indexed searches to no avail.
thanks for Great article
I have learn so much with you guys, live longer and prosper my friends.
I faced a problem in generating ssh keys, thank you for helping in git authorisation.
See user frendly answer @ https://etechroom.com/generate-ssh-keys-on-windows-10/
I hadn’t thought of using containers but that’s a great idea. Thanks so much for sharing!
thank you for the clear explanation
I use often use Ubuntu for developing, but these days I also need Photoshop for my work and this is the reason I had problem and I did not know how to create SSH-key using Git Bash! That was almost same 😉
Thanks
Cool photo of the green bench! 🙂
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.
Thanks a lot, good stuff. It saved me some time
@Max
add comment with -C option, while generating your keys
Really useful thanks for the post.
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
I have created a key that I use to connect to a git repos. When I commit, my username and domain ([email protected]) 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.