SSH Key Setup
SSH (Secure Shell) keys are a safe way to authenticate with GitHub without having to enter your username and Personal Access Token every time you push or pull code.
🗝️ How SSH Keys Work
- Commands Reference: Essential command set from
inittopush/pull. - Branching Basics: Master the core concepts and the modern
git switchcommand. - Branching Strategies: Professional workflows like Gitflow (Main, Develop, Feature, Hotfix).
- Git Rebase Guide: Technical deep dive into history manipulation and rebase safety.
- Advanced Remotes: Managing multi-remote setups (Origin vs. Upstream) and URL switching.
Step 1: Check for Existing Keys
Open your terminal and check if you already have SSH keys generated:
ls -al ~/.sshLook for files like id_ed25519.pub or id_rsa.pub. If you don't see them, proceed to the next step.
Step 2: Generate a New SSH Key
We recommend using the Ed25519 algorithm for the best security and performance.
ssh-keygen -t ed25519 -C "your_email@example.com"When prompted to "Enter a file in which to save the key," just press Enter to use the default location.
Step 3: Add Key to the SSH Agent
The SSH Agent manages your keys in memory so you don't have to re-enter your passphrase.
# Start the agent in the background
eval "$(ssh-agent -s)"
# Add your private key to the agent
ssh-add ~/.ssh/id_ed25519Step 4: Add the SSH Key to GitHub
- Copy your public key to your clipboard:
cat ~/.ssh/id_ed25519.pub - Go to Settings on GitHub.
- Click SSH and GPG keys in the sidebar.
- Click New SSH key and paste your key. Give it a descriptive title (e.g., "Work Laptop").
Step 5: Test Your Connection
Verify that everything is set up correctly:
ssh -T git@github.comIf you see: "Hi username! You've successfully authenticated...", you are ready to go!
[!CAUTION] Protect Your Private Key Your private key (
id_ed25519WITHOUT the.pub) is your identity. If someone gets access to it, they can impersonate you on GitHub. Keep it secret, keep it safe.