Search code examples
gitintellij-ideasshphpstormjetbrains-ide

JetBrains (IntelliJ, PhpStorm, WebStorm ...) private git repository with SSH key


My New Web Server need authentication with RSA 2048 key.

I therefore generated a key, I placed the ir_rsa and id_rsa.pub files in my home folder ~/.ssh (Windows 10).

But When I use the cvs comment (for pull or push) I get an error :

enter image description here

The Error Log is (with built-in SSH executable) :

15:14:14.657: [MyProject] git -c core.quotepath=false fetch origin --progress --prune java.io.IOException: There was a problem while connecting to mywebhost.fr:22 at com.trilead.ssh2.Connection.connect(Connection.java:791) at com.trilead.ssh2.Connection.connect(Connection.java:577) at org.jetbrains.git4idea.ssh.SSHMain.start(SSHMain.java:171) at org.jetbrains.git4idea.ssh.SSHMain.main(SSHMain.java:137) Caused by: java.io.IOException: Key exchange was not finished, connection is closed. at com.trilead.ssh2.transport.KexManager.getOrWaitForConnectionInfo(KexManager.java:92) at com.trilead.ssh2.transport.TransportManager.getConnectionInfo(TransportManager.java:230) at com.trilead.ssh2.Connection.connect(Connection.java:743) ... 3 more Caused by: java.io.IOException: Cannot negotiate, proposals do not match. at com.trilead.ssh2.transport.KexManager.handleMessage(KexManager.java:413) at com.trilead.ssh2.transport.TransportManager.receiveLoop(TransportManager.java:754) at com.trilead.ssh2.transport.TransportManager$1.run(TransportManager.java:469) at java.lang.Thread.run(Thread.java:745) fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.

The Error Log is (with "Settings > Version Control > git > SSH Executable" to "native") :

15:13:50.031: [MyProject] git -c core.quotepath=false fetch origin --progress --prune Permission denied (publickey). fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.

If I use the Git command in terminal the pull or push command works good :

enter image description here

What should I do to use PhpStorm's VCS buttons?

  • I tried to set Settings > Version Control > git > SSH Executable to "native" : Same problem
  • I tried to Install putty utility, run "Pageant" services and import my private key : Same problem
  • I tried to run ssh-add : Same problem

enter image description here

  • I tried to configure the ~/.config file: Same problem

Host myHost.fr
Hostname myHost.fr User myloginuser IdentityFile C:\Users\username.ssh\id_rsa

My Git version is : 2.10.2.windows.1 (downloaded from https://git-scm.com/download/win)

My OS is Windows 10


[Edit] Solution : Thank you to Dmitriy Smirnov, I found the Solution :

In the C:\Program Files\Git\cmd folder you will find the file start-ssh-pageant.cmd.

Before launching it is necessary to create an environment variable:

Name: SSH_AUTH_SOCK
Value: C:\Users\username\.ssh\.ssh-pageant-username

(I tried with Pagent from Putty, and ssh-agent from Git Bash but it did not work)


Solution

  • IntelliJ built-in SSH executable does not support strong security keys at the moment: https://youtrack.jetbrains.com/issue/IDEA-140196

    Also, your keys are protected by a passphrase, that is why Native SSH does not work. IDE is not a terminal so cannot handle the prompt for a passphrase issued by the git

    As a workaround, you could load the key to a ssh-agent, so executing git pull from the command prompt does not prompt you for a passphrase, and use Native SSH.