Banner da postagem: How to Set Up SSH for GitHub and Bitbucket on Windows and Linux

How to Set Up SSH for GitHub and Bitbucket on Windows and Linux

Learn how to set up SSH on GitHub and Bitbucket for Windows and Linux. A practical guide to securely clone, configure, and authenticate repositories.


Authenticating with SSH eliminates the need for passwords when working with Git repositories. Here’s how to generate, register, and use your SSH key in just a few minutes.


Table of Contents


How to generate an SSH key on Windows

Open PowerShell or Command Prompt and run:

ssh-keygen -t ed25519 -C "your-email@example.com"
  • Press Enter to accept the default location:
    C:\Users\YourUser\.ssh\id_ed25519
  • Enter a secure passphrase (optional, but recommended)
  • Confirm the passphrase

How to copy the public key on Windows

# Copy to clipboard
Get-Content C:\Users\YourUser\.ssh\id_ed25519.pub | Set-Clipboard

# Or just display it in the terminal
cat C:\Users\YourUser\.ssh\id_ed25519.pub

How to generate an SSH key on Linux

ssh-keygen -t ed25519 -C "your-email@example.com"
  • Press Enter to accept the default location:
    ~/.ssh/id_ed25519
  • Enter a secure passphrase (optional)
  • Confirm the passphrase

How to copy the public key on Linux

# Copy to clipboard (Ubuntu/Debian)
cat ~/.ssh/id_ed25519.pub | xclip -selection clipboard

# Install xclip if needed
sudo apt install xclip

# Or just display it
cat ~/.ssh/id_ed25519.pub

How to add the SSH key to GitHub

  1. Log in to your GitHub account
  2. Go to your account settings
  3. Look for a menu such as "SSH Keys", "Add SSH key", or similar
  4. Paste your public key into the appropriate field
  5. Save changes

How to add the SSH key to Bitbucket

  1. Log in to your Bitbucket account
  2. Go to account settings
  3. Find a menu like "SSH Keys" or "Add Key"
  4. Paste your public key
  5. Save changes

How to configure Git with your name and email

# Set name and email
git config --global user.name "Your Name"
git config --global user.email "your-email@example.com"

# Test connection with GitHub
ssh -T git@github.com

# Test connection with Bitbucket
ssh -T git@bitbucket.org

How to use multiple SSH keys

If you use one key for GitHub and another for Bitbucket, create a config file in your .ssh directory.

Windows:
C:\Users\YourUser\.ssh\config

Linux:
~/.ssh/config

# GitHub
Host github.com
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_ed25519_github

# Bitbucket
Host bitbucket.org
    HostName bitbucket.org
    User git
    IdentityFile ~/.ssh/id_ed25519_bitbucket

How to clone repositories with SSH

Use the following command instead of the HTTPS URL:

git clone git@github.com:user/repository.git
git clone git@bitbucket.org:user/repository.git

Now you can work with your repositories more securely and conveniently using SSH on GitHub and Bitbucket.

How to Set Up SSH for GitHub and Bitbucket on Windows and Linux | pr.dev