Git Login via SSH
Last updated by Nabeel Hassan
Follow these steps to authenticate Git using SSH.
1. Check for Existing SSH Keys
Check if an SSH key already exists:
ls -al ~/.sshIf files like id_rsa and id_rsa.pub are present, you already have a key.
2. Generate a New SSH Key (If Needed)
Generate a new SSH key:
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"Press Enter to save it in the default location and set an optional passphrase.
3. Start SSH Agent and Add Your Key
Ensure the SSH agent is running:
eval "$(ssh-agent -s)"Add your key:
ssh-add ~/.ssh/id_rsa4. Copy SSH Key to Git Provider
Copy the public key:
cat ~/.ssh/id_rsa.pubGo to GitHub/GitLab/Bitbucket → SSH and GPG keys → New SSH Key, then paste the copied key.
5. Test SSH Connection
Test your connection:
GitHub:
ssh -T git@github.comGitLab:
ssh -T git@gitlab.comBitbucket:
ssh -T git@bitbucket.orgA successful connection returns a message like:
Hi <username>! You've successfully authenticated, but GitHub does not provide shell access.6. Configure Git User Information
Set your Git username and email:
git config --global user.name "Your Name"git config --global user.email "your_email@example.com"7. Clone a Repository Using SSH
If cloning a new repository, use:
git clone git@github.com:your-username/your-repo.gitAfter completing these steps, you can use Git via SSH without entering your password every time. 🚀