Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IntelliJ IDEA git Permission denied (publickey)

I got a strange problem with using git on IntelliJ IDEA on Windows 10. If I want to access the remote repo on GitLab, I always get Permission denied (publickey). Everything I found here or via Google didn't solve the problem. I tried:

  1. Setting the ssh executable to Native
  2. Converting my public key from Putty to ssh-keygen style
  3. Removing known_hosts

I also tried to access the repo with Git Bash, it works fine like that. Another interesting fact is that after removing known_hosts, I got "Host key verification failed". I had to use Git Bash once to recreate the known_hosts entry, after that I got the Permission denied error again. Somehow I don't get asked for any user input.

like image 586
Peter Oettig Avatar asked Jun 29 '16 16:06

Peter Oettig


People also ask

How do I change my git password in IntelliJ?

In the Settings/Preferences dialog Ctrl+Alt+S , select Appearance and Behavior | System Settings | Passwords on the left. Select how you want IntelliJ IDEA to process passwords for Git remote repositories: In native Keychain: select this option to use native Keychain to store your passwords.

Why do I get permission denied in Git bash?

The Bash permission denied error indicates you are trying to execute a file which you do not have permission to run. To fix this issue, use the chmod u+x command to give yourself permissions. If you cannot use this command, you may need to contact your system administrator to get access to a file.

Could not read from remote repository in IntelliJ?

Please make sure you have the correct access rights and the repository exists. Using the built-in terminal of IntelliJ, executing git -c core. quotepath=false fetch origin --progress --prune , it works just as it should.


4 Answers

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.org
IdentityFile 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

like image 58
Sahil Avatar answered Oct 12 '22 08:10

Sahil


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 /.

like image 29
Cristian Torres Avatar answered Oct 12 '22 10:10

Cristian Torres


Update IDEA 2021.2.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. Unset environment variable HOME -- it still breaks ssh in this version of IDEA.
  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.

like image 5
cb4 Avatar answered Oct 12 '22 09:10

cb4


I was having this same issue, and while it did have to do with the public key, my issue was concerned with WSL2/Linux and windows .ssh folders. My keys were in my WSL2/linux folder system, but intelliJ was looking in my windows folder system.

I copied my rsa keys from WSL2 to windows, and it worked automatically. In fact, I attempted to have it fail again by removing the keys from the Windows folders, but intelliJ must have it's own keylocker solution, because even without the keys in the Windows .ssh folder intelliJ continued to work.

For a screen capture explaining it you can see it here https://vimeo.com/558267383/74d55415c4

like image 1
POBrien Avatar answered Oct 12 '22 08:10

POBrien