
Security Ssh in Git
🔒 Security: Using SSH with Git
Using SSH for Git authentication is safer and avoids entering your username/password every time. Follow these steps to set up SSH securely.
📌 Steps to Securely Use SSH in Git
1️⃣ Check for Existing SSH Keys
Before generating a new key, check if you already have one:
eval "$(ssh-agent -s)"
Add your SSH key:
ssh-add ~/.ssh/id_ed25519
4️⃣ Add Your SSH Key to GitHub
1️⃣ Copy your SSH key to the clipboard:
cat ~/.ssh/id_ed25519.pub
2️⃣ Go to GitHub → Settings → SSH and GPG Keys
3️⃣ Click "New SSH Key", paste the key, and save.
5️⃣ Test Your SSH Connection
Run:
ssh -T git@github.com
If successful, you'll see:
Hi your-username! You've successfully authenticated.
6️⃣ Use SSH for Git Operations
Instead of HTTPS, use SSH when cloning
git clone git@github.com:your-username/repository-name.git
To switch an existing repo to SSH:
git remote set-url origin git@github.com:your-username/repository-name.git
🎯 Summary
✅ Check for SSH keys → ls -al ~/.ssh
✅ Generate new SSH key → ssh-keygen -t ed25519 -C "email@example.com"
✅ Add key to agent → ssh-add ~/.ssh/id_ed25519
✅ Add key to GitHub → Copy & paste id_ed25519.pub
✅ Test connection → ssh -T git@github.com
✅ Use SSH for Git → git clone git@github.com:username/repo.git