Development
Ssh Keygenload Mac

🔑 macOS SSH Key Setup (with Keychain)

When connecting to Bitbucket/GitHub/GitLab via SSH, you might see:

Permission denied (publickey).

This happens because your SSH agent has no key loaded.


1. Generate an SSH Key (if you don’t already have one)

ssh-keygen -t ed25519 -C "[email protected]" -f ~/.ssh/[email protected]

This creates:


2. Add Key to macOS Keychain

ssh-add --apple-use-keychain ~/.ssh/[email protected]

Check if loaded:

ssh-add -l

3. Configure ~/.ssh/config

Edit (or create) the file:

nano ~/.ssh/config

Add:

Host bitbucket.org
    HostName bitbucket.org
    User git
    IdentityFile ~/.ssh/[email protected]
    UseKeychain yes
    AddKeysToAgent yes

💡 This ensures:

  • The key auto-loads into Keychain.
  • Git automatically uses this key for Bitbucket.

4. Upload Public Key to Bitbucket

Copy your key:

Go to Bitbucket → Personal Settings → SSH Keys → Add Key → paste it.


5. Test Connection

Expected output:

authenticated via ssh key.
You can use git to connect to Bitbucket!

6. (Optional) Linux Setup

If using Linux, add this to ~/.bashrc or ~/.zshrc:

eval "$(ssh-agent -s)"
ssh-add ~/.ssh/[email protected]

✅ Executive Summary

  • Problem: SSH agent had no key → “Permission denied”.
  • Fix: Load key with ssh-add and persist via Keychain.
  • Best Practice: Use ~/.ssh/config + Keychain → no more manual ssh-add.

🧙 AI Wizard - Instant Page Insights

Click the button below to analyze this page.
Get an AI-generated summary and key insights in seconds.
Powered by Perplexity AI!