Git Permission denied (publickey)

Create ssh_config with

Host git_hostname # probably bitbucket.org
  IdentityFile /d/ssh/id_rsa

It should be in ~/.ssh/config. You should be able to find out what configuration is your client reading when running ssh -vvv bitbucket.org.


It can also happen when u added SSH support in your repository. And can be fixed by following steps :

  1. Goto SSH

    cd ~/.ssh
    
  2. List existing Keys

    ls -al ~/.ssh
    
  3. Use this command to create the SSH keys

    ssh-keygen -t rsa -C "[email protected]"
    
  4. Use this command to start your ssh-agent if it's not already running

    eval `ssh-agent`
    
  5. Then add your private key file to SSH

    ssh-add ~/.ssh/<private_key_file>
    
  6. Copy and paste your key in Bitbucket/ Github with

    cat ~/.ssh/<public_key_file> | pbcopy
    
  7. Sometime it does not persists between reboot. Then you have to add below lines in .ssh/config (For Mac)

    Host *
        UseKeychain yes
        AddKeysToAgent yes
        IdentityFile ~/.ssh/<private_key_file>
    

Tags:

Git

Ssh

Bitbucket