Step 1: Verify SSH Keys
First, ensure you have SSH keys set up on your machine and added to your GitHub account.
- Check for existing SSH keys:
ls -al ~/.ssh
Look for files named
id_rsa
andid_rsa.pub
or similar. - Generate a new SSH key (if necessary):
ssh-keygen -t rsa -b 4096 -C "[email protected]"
Follow the prompts to save the key (default location is fine).
- Add your SSH key to the SSH agent:
eval "$(ssh-agent -s)" ssh-add ~/.ssh/id_rsa
- Add the SSH key to your GitHub account: Copy the contents of your public key file to the clipboard:
cat ~/.ssh/id_rsa.pub
Then, add it to your GitHub account by going to Settings > SSH and GPG keys > New SSH key.
Step 2: Update Remote URL
- Navigate to your local repository:
cd /path/to/your/repo
- Get the current remote URL:
git remote -v
- Update the remote URL to use SSH: Replace
origin
with the name of your remote if it’s different.git remote set-url origin [email protected]:username/repo.git
Replace
username
with your GitHub username andrepo
with the name of your repository. - Verify the change:
git remote -v
You should see the SSH URL listed.
Step 3: Test the Connection
- Test the SSH connection:
ssh -T [email protected]
You should see a success message like “Hi username! You’ve successfully authenticated, but GitHub does not provide shell access.”
- Fetch from the remote to ensure everything is working:
git fetch
If everything is set up correctly, your repository should now be using SSH instead of HTTPS.