
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
- How to copy the public key on Windows
- How to generate an SSH key on Linux
- How to copy the public key on Linux
- How to add the SSH key to GitHub
- How to add the SSH key to Bitbucket
- How to configure Git with your name and email
- How to use multiple SSH keys
- How to clone repositories with SSH
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
- Log in to your GitHub account
- Go to your account settings
- Look for a menu such as "SSH Keys", "Add SSH key", or similar
- Paste your public key into the appropriate field
- Save changes
How to add the SSH key to Bitbucket
- Log in to your Bitbucket account
- Go to account settings
- Find a menu like "SSH Keys" or "Add Key"
- Paste your public key
- 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.