How to add SSH Private Key to Intellij for Git
Answered
When I use Git, I usually use the command line. so to push changes to the server. I add the public key to the SSH session using:
$ eval "$(ssh-agent -s)"
ssh-add "D:/Dev/Books Spaces/Version Control with Git and GitHub/SSH/key"
Enter passphrase for D:/Dev/Books Spaces/Version Control with Git and GitHub/SSH/key:
Identity added: D:/Dev/Books Spaces/Version Control with Git and GitHub/SSH/key (me*****d@outlook.com)
Now I would like to use intellij using SSH. How Can I add the private key to intellij? Right now it prints the message:
Please sign in to leave a comment.
IntelliJ fully relies on the command line git, so one does not need to enter any keys in the IDE. Just configure git in the command line to work, and it should work in the IDE as well.
Note, however, that environment inheritance matters. If you start ssh-agent when IDE is running, or does it in a non-native shell, IDE will not have corresponding environment variables set.
So make sure you configure ssh-agent in a way it is available in the native shell (cmd.exe for windows), and make sure to start IDE after the agent.
See also https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000114504--Solved-Git-SHH-Private-Key-PAssPhrase
Hi Dimitriy,
I don't understand. I started git bash on windows. added SSH key. opened intellij. still ame error.
"So make sure you configure ssh-agent in a way it is available in the native shell (cmd.exe for windows), and make sure to start IDE after the agent." How Can I do that for git bash on windows?
> I started git bash
Git Bash is not a native shell on Windows. It is an isolated environment, and other applications started in a regular way do not have access to it.
You need to start the agent in a way it is available in cmd.exe, e.g GitForWindows includes specific scripts for that. Or start IntelliJ via command line from GitBash so the environment is inherited
Dimitry, your answer does not really answer the OP's question. I think the real answer is that phpstorm lacks support for git or partial support (since they do allow to setup remotes but partially without including all features). There are IDE's that offer great git features like setting private keys per project (GUI easy to setup). Too bad phpstorm has only limited support for such tasks. Phpstorm still is at the top right now but they should really follow some of the Netbean's UX priciples and features.
https://stackoverflow.com/questions/38105563/intellij-idea-git-permission-denied-publickey
Dmitriy Smirnov, thank you for your answer. It was helpful.
I used iTerm and was running the agent in the same time with IDEA.
Why not specify a key path as in TortoiseGit?
Intellij is kind of stuck when it comes to that. You haven't been able to do this for ten years!
That sucks and the forums are full of it in the forums! I still have to work with other tools to make it work easily and smoothly with Git!
Steven
I was able to work around this for Cygwin by setting GIT_SSH_COMMAND to /bin/ssh in my Windows user environment variables. I then added a setx line to my .bashrc where I start the ssh-agent, restarted my ssh-agent, and restarted Intellij.
I think when Intellij invokes the Cygwin git binary without the full Cygwin environment, it picks up the Windows ssh before the Cygwin ssh in the path. It's probably looking for keys in the Windows user home instead of the Cygwin user home.
The Stackoverflow link above hints at this solution, but the answers are complicated and suggest that you either need to use Windows OpenSSH, edit your ssh configurations, or run Intellij from the command line.
>> I started git bash
>Git Bash is not a native shell on Windows.
I got help from here:
https://docs.microsoft.com/en-us/windows-server/administration/openssh/openssh_install_firstuse?tabs=powershell
and
https://docs.microsoft.com/en-us/windows-server/administration/openssh/openssh_keymanagement
It was necessary for me to follow Ken's process above (see comment by Ken, dtd Oct. 18, 2021), in order to get intelliJ to be able to clone any bitbucket repository using ssh keys
In KDE Plasma:
1. Right click on “Application Launcher” (in the lower-left corner) and select “Edit Applications”
2. Navigate to the IntelliJ menu (or whatever you called it)
3. In the “Program” field enter “eval $(ssh-agent); ssh-add <path_to_your_private_key>; /opt/IntelliJ/bin/idea.sh” without the quotes. (On my system “/opt/IntelliJ” is the symlink to the current IntelliJ installation directory.)
5. Click “Save” and close the window.
When you save the Application Launcher settings, it will reformat your “script” into the format it considers “correct” - leave it be.
Now whenever I click on the IntelliJ menu item, I am first presented with the password pop-up window, where I must enter the private key password. After that the IDE opens with full git capability.