How to use a different ssh key

Answered

I have 2 github accounts
A company one and a personal one

I use cygwin to manage my ssh keys and connect to Github

Everything works fine In IntelliJ when using the corporate account since it uses the the default .ssh/id_rsa key

Everthing works fine in Cygwin using my Personal Account since I can use the the "ssh-add ~/.ssh/ide_rsa_otherkeyfile" command and then use all git commands via command line

But IntelliJ always default to the "id_rsa" file so I can not connect to my personal repo.

Is there a way for IntelliJ to use the other rsa key?


All this RSA and cygwin is way above my linux command line experience level.

Note:
I also created the config file to facilitate multiple github accounts

# Default GitHub user (corporate account)
Host github.com
HostName github.com
User git
IdentityFile /Users/username/.ssh/id_rsa

# Client user (personal account)
Host github-client
HostName github.com
User git
IdentityFile /Users/username/.ssh/id_rsa_perso

In short what this does is tells SSH to use the client key when connecting to the server github-client, which is really github.com.



If no one has a solution I am aware that it would be easier to invite my corporate account as a contributor but then I woul have commits under 2 seperate email account :(
1
7 comments
Avatar
Permanently deleted user

Hi Stephane,

Try to set the following option to 'Native' - 'Project Settings - Version Control - VCSs - Git - SSH Executable'

Regards, Denis

5
Avatar
Permanently deleted user

I set the SSH Executable to Native - and I also followed the following instructions: 

https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/

The important part here is this: 

ssh-add ~/.ssh/different_rsa

That's what got it rolilng is adding the new identity to the ssh agent. 

1
Avatar
Permanently deleted user

I am having this problem as well and using the Native SSH, adding my second SSH key to the ssh-agent, and using both keychain and gnome-keyring aren't helping. IntelliJ IDEA always defaults to using id_rsa in Crostini on Chrome OS.

0

> IntelliJ IDEA always defaults to using id_rsa in Crostini on Chrome OS.

It defaults to id_rsa only when Built-in SSH is in use and NO .ssh/config file is present, specifying the key to use.

With Native SSH, IDE literally does nothing expecting command line ssh client to handle authentication. What could cause Native to fail is adding the keys to agent AFTER IDE is started. In this case, the SSH_AUTH_SOCK environment variable is not available in the IDE context and commands issues by the IDE cannot use ssh-agent.

The correct sequence should be: start ssh-agent - add keys - start IDE.

0

I can't find SSH Executable in phpStorm 2019.2.3 to set that option to native. Did you remove it or move to somewhere else?

Right now IDE wants to use default ssh key and each time is asking for password to my key on startup. Is the remember option only valid for current session?

 

0

> I can't find SSH Executable in phpStorm 2019.2.3 to set that option to native

Native is default since 2018.3, and the only option since 2019.1

> Right now IDE wants to use default ssh key and each time is asking for password to my key on startup

Do you have .ssh/config in place?

Does it work fine in the system shell? (Bash on Linux, or Windows Command Prompt)

> Is the remember option only valid for current session?

No, it should be saved according to the Settings | Appearance & Behavior | System Settings | Passwords. Passwords won't be saved if for some reason IDE can not access the specified storage. Check logs for details.

0

>> Is the remember option only valid for current session?

> No, it should be saved according to the Settings | Appearance & Behavior | System Settings | Passwords. Passwords won't be saved if for some reason IDE can not access the specified storage. Check logs for details.

"forget password option after restart" was set by default, this is why I still was prompted about password.

> Do you have .ssh/config in place?

I have just installed phpStorm on my fresh system and for some reason I had to convert my keys from putty format to openSSH format again. Simply copying openSSH keys from old system was causing problems, but it is not related with IDE.

Right now it should work fine.

 

0

Please sign in to leave a comment.