DEV Community

Neema Adam for ClickPesa

Posted on

Setting up SSH Keys for Github, GitLab, and Bitbucket in one windows pc

What are Github, Gitlab and Bitbucket?

Github, GitLab, and Bitbucket are all popular web-based Git repository hosting services that allow developers to collaborate on code and manage version control.

GitHub is the most well-known of the three and is used by millions of developers worldwide. It offers both free and paid plans and is a popular choice for open-source projects.

GitLab is another web-based Git repository hosting service that offers both free and paid plans. It is known for its built-in continuous integration and deployment features, making it a popular choice for DevOps teams.

Bitbucket is a Git repository hosting service that is owned by Atlassian, the company behind popular products like Jira and Confluence. It offers both free and paid plans and is known for its tight integration with other Atlassian products.

All three services offer similar functionality and are widely used by developers for managing code and collaborating on projects.

Connection method

There are several methods available to connect to Github, GitLab, or Bitbucket, including HTTPS and SSH. HTTPS is the default method and uses a username and password for authentication. SSH, on the other hand, uses a public and private key pair for authentication.

Using SSH has several advantages over HTTPS. First, it is more secure because it uses encryption to protect your credentials. Second, it is more convenient because you don’t need to enter your username and password every time you push or pull code. Finally, it allows for more fine-grained control over access to your repositories.

This guide shows you how to set up SSH keys for Github, GitLab, and Bitbucket on your Windows PC.

While SSH has several advantages over HTTPS, there are also some potential disadvantages to consider.

One is that setting up SSH requires more initial configuration than HTTPS. Additionally, if you lose your private key or it is compromised, it can be difficult to recover access to your repositories. Finally, some corporate firewalls may block SSH traffic, which could prevent you from using it to connect to remote repositories.

Setting up SSH Keys for Github, GitLab, and Bitbucket in One Windows PC

SSH keys are a secure way to authenticate with remote Git repositories like Github, GitLab, and Bitbucket. In this guide, we will show you how to set up SSH keys for all three services on your Windows PC.

Step 1: Check for existing SSH keys

Before generating new SSH keys, we need to check whether any SSH keys already exist on our machine. Open the Git Bash terminal by right-clicking on your desktop and selecting “Git Bash Here”. Then, enter the following command in the terminal:

ls -al ~/.ssh
Enter fullscreen mode Exit fullscreen mode

If any files with names like id_rsa or id_rsa.pub exist in the output, you already have an SSH key pair. If not, we will generate a new key pair in the next step.

Step 2: Generate a new SSH key pair
In the Git Bash terminal, enter the following command to generate a new SSH key pair:

ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
Enter fullscreen mode Exit fullscreen mode

This command will prompt you for a file name and passphrase.

Step 3: Add the SSH key to Github, GitLab, and Bitbucket

Next, we need to add the SSH key to our Github, GitLab, and Bitbucket accounts.

Github

  1. Log in to your Github account and go to “Settings”.
  2. Click on “SSH and GPG keys”.
  3. Click on “New SSH key”.
  4. Give your key a title and paste the contents of your id_rsa.pub file into the “Key” field.
  5. Click “Add SSH key”.

GitLab

  1. Log in to your GitLab account and go to “Settings”.
  2. Click on “SSH Keys”.
  3. Give your key a title and paste the contents of your id_rsa.pub file into the “Key” field.
  4. Click “Add key”.

Bitbucket

  1. Log in to your Bitbucket account and go to “Settings”.
  2. Click on “SSH keys”.
  3. Click on “Add key”.
  4. Give your key a label and paste the contents of your id_rsa.pub file into the “Key” field.
  5. Click “Add key”.

Step 4: Test the SSH connection

To test the SSH connection, enter the following command in the Git Bash terminal:

ssh -T git@github.com
Enter fullscreen mode Exit fullscreen mode

Replace “github.com” with “gitlab.com” or “bitbucket.org” to test the connection to those services.

If the SSH connection is successful, you should see a message like “Hi username! You’ve successfully authenticated, but GitHub does not provide shell access.”

Congratulations! You have now set up SSH keys for Github, GitLab, and Bitbucket on your Windows PC.

Top comments (1)

Collapse
 
patricklusaya profile image
Patrick Lusaya

you are a life saver !!!