IntelliJ IDEA git Permission denied (publickey) IntelliJ IDEA git Permission denied (publickey) windows windows

IntelliJ IDEA git Permission denied (publickey)


I faced this problem while connecting bitbucket cloud from my Intellij 2019.2 , which thankfully got solved with the following steps. Please note that these steps are to be carried out after you successfully generate and add ssh-public key to your bitbucket/github/gitlab profile.

  1. Open Git-SCM ssh_config file present in Git-SCM installation directory.It's default location in Windows (for 64 bit) is in C:\Program Files\Git\etc\ssh\
  2. Add the following lines into ssh_config
Host *your-gitlab-or-github-or-bitbucket-hostname*IdentityFile *your-ssh-rsa-privatekey-file-with-absolute-path*

for e.g

Host bitbucket.orgIdentityFile C:/Users/Sahil/.ssh/id_rsa

Source:https://intellij-support.jetbrains.com/hc/en-us/community/posts/360004124959-IntelliJ-2019-1-3-Can-t-access-git-using-SSH-keys


Update IDEA 2020.3

The bug in Sahil's answer has been fixed and Christian's solution is not needed with the correct entry in your ssh config file for the most common case of one key for one or more hosts. Additional options for complex configurations, such as multiple keys to the same or multiple hosts, can be found in Maddes comprehensive answer on superuser.

ANY inconsistency between ssh-agent and ssh-add leads to a situation where some things work and some don't.

For example, I had the Windows OpenSSH agent running but my path pointed first to the Git for Windows ssh-add. Many such failures are possible given the many ssh implementations out there, so know that you know where things are running from.

To get ssh working in IDEA...


Git for Windows

  1. Install Git for Windows. I put it in C:\Git since, as a standard user without an elevated install, I couldn't write to C:\Program Files.
  2. In Control Panel | User Accounts | Change my environment variables add the Git usr\bin folder to the path after the cmd folder entry already there (e.g. C:\Git\usr\bin for my installation).
  3. If you set the environment variable HOME (like I did for Git) delete it; IDEA breaks if it's set (been working this with JetBrains support all week).
  4. In a Windows cmd.exe console, run start-ssh-agent.cmd to start the agent
  5. In IDEA in Settings | SSH Configurations | Authentication type: set it to Key pair OpenSSH or PuTTY and test your connection. Then, make a small change and test Commit and push....

Windows OpenSSH

  1. In Control Panel | User Accounts | Change my environment variables add C:\Windows\System32\OpenSSH to your path. Make sure no other ssh implementation is ahead of this in the path!
  2. Start the OpenSSH agent in Task Manager | Services (or any number of other ways)
  3. Set your IDEA SSH Configuration as #5 above

Keep in mind that, on Windows, ssh in IDEA uses the environment available in a standard Windows command-line console (cmd.exe). If git operations work there, then with the above steps in place, they'll work in IntelliJ.


It has been really long since OP but here is my solution on an execution basis:

  1. You need to open a prompt and set the ENVVAR GIT_SSH_COMMAND.
  2. You need to open IntelliJ from that same prompt.

Example:

> set GIT_SSH_COMMAND=ssh -i C:\\path\\to\\not\\default\\key> idea

Also the path to not-default-key should use ~ instead of %userprofile% or paths unix-like using /.