Tell Git which SSH key to use

Submitted by Peter Majmesku on Mon, 05/21/2018 - 13:24

I could not push to Bitbucket. I have multiple accounts on Bitbucket, so the issue could have to do with. So I was going to configure my project's Git config to distinct between several private SSH keys for 1 host. A thread on Stackoverflow was helpful, to learn how to tell Git which SSH key it has to use for a specific remote. Because all the the time my access has been refused with the following error:

repository access denied.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Firstly I must set the host in my ~/.ssh/config file:

Host bitbucket_privat
  HostName bitbucket.org
  User peter_majmesku
  IdentityFile ~/.ssh/bitbucket_privat  

Then I must edit the PROJECT_DIRECTORY/.git/config file in my project to assign the SSH config:

[remote "origin"] 
  url = bitbucket_privat:peter_majmesku/permissions_by_term.git 
  fetch = +refs/heads/*:refs/remotes/origin/*

Finished! Afterwards I am finally able to push to Bitbucket:

peter@NB8 permissions_by_term (8.x-1.x) $ git push
Counting objects: 1617, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (847/847), done.
Writing objects: 100% (1617/1617), 1.83 MiB | 5.73 MiB/s, done.
Total 1617 (delta 923), reused 1225 (delta 696)
remote: Resolving deltas: 100% (923/923), done.
To bitbucket_privat:peter_majmesku/permissions_by_term.git
* [new branch] 8.x-1.x -> 8.x-1.x
Tags

Add new comment

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.
CAPTCHA This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.