SSH Key Setup
This guide explains how to generate SSH keys and configure them for use with GitHub and remote servers.
Generate an SSH Key
- Windows
- macOS
- Linux
# Generate a new Ed25519 SSH key
ssh-keygen -t ed25519 -C "your.email@example.com"
# When prompted for file location, press Enter for default (C:\Users\YOU\.ssh\id_ed25519)
# Optionally set a passphrase for additional security
# Start the SSH agent (if not running)
Get-Service ssh-agent | Set-Service -StartupType Automatic
Start-Service ssh-agent
# Add your key to the agent
ssh-add $env:USERPROFILE\.ssh\id_ed25519
If ssh-agent is not available, enable OpenSSH:
- Open Settings → Apps → Optional Features
- Add OpenSSH Client if not installed
# Generate a new Ed25519 SSH key
ssh-keygen -t ed25519 -C "your.email@example.com"
# When prompted for file location, press Enter for default (~/.ssh/id_ed25519)
# Optionally set a passphrase for additional security
# Start the SSH agent
eval "$(ssh-agent -s)"
# Add your key to the agent
ssh-add ~/.ssh/id_ed25519
To persist the key in your keychain across restarts, add to ~/.ssh/config:
Host *
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_ed25519
# Generate a new Ed25519 SSH key
ssh-keygen -t ed25519 -C "your.email@example.com"
# When prompted for file location, press Enter for default (~/.ssh/id_ed25519)
# Optionally set a passphrase for additional security
# Start the SSH agent
eval "$(ssh-agent -s)"
# Add your key to the agent
ssh-add ~/.ssh/id_ed25519
Copy Your Public Key
You'll need your public key to add to GitHub or remote servers.
- Windows
- macOS
- Linux
# Copy to clipboard
Get-Content $env:USERPROFILE\.ssh\id_ed25519.pub | Set-Clipboard
# Or display to copy manually
Get-Content $env:USERPROFILE\.ssh\id_ed25519.pub
# Copy to clipboard
pbcopy < ~/.ssh/id_ed25519.pub
# Or display to copy manually
cat ~/.ssh/id_ed25519.pub
# Copy to clipboard (requires xclip)
xclip -selection clipboard < ~/.ssh/id_ed25519.pub
# Or display to copy manually
cat ~/.ssh/id_ed25519.pub
Add Key to GitHub
Once you have your SSH key, add it to GitHub:
Multiple SSH Keys
If you need different keys for different services (e.g., work vs personal):
-
Generate additional keys with different names:
ssh-keygen -t ed25519 -C "personal@example.com" -f ~/.ssh/id_ed25519_personal -
Configure
~/.ssh/configto use the right key:# Work GitHub
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519
# Personal GitHub
Host github-personal
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_personal -
Clone using the configured host alias:
git clone git@github-personal:username/repo.git
Related
- Git Commit Signing - Sign your commits
- GitHub Setup - GitHub-specific configuration
- GitHub SSH Troubleshooting - Help with common SSH issues