Creating SSH Keys for GitHub
1. Install Git
First, ensure that Git is installed on the new PC. You can install it by downloading from the official site or using your system’s package manager.
- Windows: Git for Windows
-
Linux:
1 2
sudo apt update sudo apt install git
-
macOS (via Homebrew):
1
brew install git
2. Configure Git with Your GitHub Account
Once Git is installed, configure it to use your GitHub account by setting your username and email:
1
2
git config --global user.name "Your GitHub Username"
git config --global user.email "your-email@example.com"
3. Set Up Authentication
There are two main ways to authenticate your GitHub account on a new PC:
Option 1: SSH Key Authentication
-
Create a New SSH Key on the new PC (if you haven’t already done so):
1
ssh-keygen -t rsa -b 4096 -C "your-email@example.com"
Follow the prompts and use the default location (
~/.ssh/id_rsa
). -
Add the SSH Key to the SSH Agent:
Start the SSH agent:
1
eval "$(ssh-agent -s)"
Add the SSH private key to the agent:
1
ssh-add ~/.ssh/id_rsa
-
Add the SSH Key to GitHub:
Copy the public key to your clipboard:
1
cat ~/.ssh/id_rsa.pub
Then, log into your GitHub account and go to Settings > SSH and GPG keys > New SSH key, paste the key, and give it a recognizable title (e.g., “New PC”).
-
Test the Connection:
1
ssh -T git@github.com
If everything is set up correctly, you’ll see a message like:
1
Hi username! You've successfully authenticated, but GitHub does not provide shell access.
Option 2: Personal Access Token (PAT) Authentication
-
Generate a Personal Access Token:
- Go to GitHub > Settings > Developer Settings > Personal Access Tokens.
- Click Generate new token and choose the necessary permissions (usually,
repo
scope is enough). - Save the generated token somewhere safe.
-
Use the Token in Git:
When you clone a repo or push changes, Git will prompt you for your username and password. Use your GitHub username as the username and the token as the password.
4. Clone or Work with Repositories
Once your authentication method is set up, you can clone your repositories:
1
2
3
git clone git@github.com:username/repository.git # For SSH
# or
git clone https://github.com/username/repository.git # For HTTPS with PAT
You’re now ready to use your GitHub account on a new PC! Let me know if you need further clarification on any steps.