How to generate SSH keys for Git authorization

SSH keys © Some rights reserved by @boetter / flickr

Securing your Git interactions with SSH keys is a fundamental aspect of software development today, offering a secure and convenient way to authenticate with remote repositories. Whether you’re an experienced developer or just starting your coding journey, understanding how to generate SSH keys for Git authorization is an essential skill to ensure the integrity and privacy of your code. In this quick guide, we’ll walk you through the process of creating SSH keys on Windows, Mac, and Linux systems, empowering you to access and collaborate on your Git projects with enhanced security.

Windows

Just follow these 5 steps:

  1. Go to this address, and download Git for Windows, 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 / 8 / 10), or C:\Documents and Settings\your_username (on Windows XP)

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 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.
  5. Be sure that you don’t copy any whitespace while copying public key’s content (id_rsa.pub)

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)

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!

Related Inchoo Services

You made it all the way down here so you must have enjoyed this post! You may also like:

Local development with Valet+ Damir Korpar
Damir Korpar, | 0

Local development with Valet+

How we developed a new Morris 4×4 Center store – case study Maja Kardum
Maja Kardum, | 1

How we developed a new Morris 4×4 Center store – case study

Ground zero – planning phase Vesna Pozderac
Vesna Pozderac, | 0

Ground zero – planning phase

21 comments

    1. 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.

  1. 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

  2. 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.

  3. 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.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <blockquote cite=""> <code> <del datetime=""> <em> <s> <strike> <strong>. You may use following syntax for source code: <pre><code>$current = "Inchoo";</code></pre>.

Tell us about your project

Drop us a line. We'd love to know more about your project.