Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I connect IntelliJ to GitHub using SSH

I have successfully configured my GitHub client to use SSH, and received the confirmatory email from GitHub that a new SSH key was added. I would like to setup IntelliJ to use SSH as well, so that I don't have to enter my Username and Password every time I interact with GitHub. I also don't want IntelliJ to save my password for me, since I am unsure how secure that would be.

The closest I have come so far is that I need to edit my ~/.ssh/config file to tell IntelliJ that there is an SSH key it can use. Unfortunately I have not managed to find an example that works.

Here is my latest attempt at a ~/.ssh/config entry:

Host IntelliJ
  HostName github.com
  User git
  IdentityFile "/Users/peter/.ssh/github_rsa"
  TCPKeepAlive yes
  IdentitiesOnly yes

I have tried restarting IntelliJ after adding that entry, but to no avail. I'm running IntelliJ Ultimate 12.1.6 on Mac OSX 10.8.5

like image 588
OldManLink Avatar asked Dec 17 '13 11:12

OldManLink


People also ask

How do I connect IntelliJ to GitHub?

Press Ctrl+Alt+S to open the IDE settings and select Version Control | GitHub. Click Add account, and in the dialog that opens, click Sign up for Github. Register your account on the Sign up for GitHub page that opens. Return to the IntelliJ IDEA settings and specify your credentials.

How do I link SSH to GitHub?

To find the GitHub SSH URL for a given repo, go to the repository's landing page and click on the green Code button. This presents three separate options to connect to Git: a GitHub SSH URL; a GitHub HTTPS URL; and.

Can you SSH in IntelliJ?

You can launch an SSH Session right from IntelliJ IDEA. By running commands in a dedicated SSH terminal, you can access data on a remote Web server or a Vagrant instance (virtual machine) via an SSH tunnel, mainly upload and download files.


4 Answers

GitHub plugin for IntelliJ lets you to save the password, so you don't have to enter it every time.

enter image description here


With keys

(adapted from Multiple SSH Keys settings for different github account, thanks to CrazyCoder comment):

  • Create ssh key pair

    $ ssh-keygen -t rsa -C "[email protected]"
    
  • Add key

    $ ~/.ssh/id_rsa_activehacker
    
  • Confirm that the key is added

    $ ssh-add -l
    
  • Modify ~/.ssh/config

    Host github.com-activehacker  
    HostName github.com  
    User git  
    IdentityFile ~/.ssh/id_rsa_activehacker
    


In IntelliJ

VCS > Checkout from Version Control > Git

Checkout from Version Control

Test

Test

As you can see, you will still have to either enter passphrase for the key pair after every IntelliJ relaunch(I believe the passphrase is kept in memory) or let IntelliJ to store it permanently.

like image 153
kukido Avatar answered Oct 23 '22 17:10

kukido


Using IntelliJ 2016.3.3 this seems very straight forward by following the steps below:

  1. Generate your keypair to use, if none exists already with

ssh-keygen

  1. Add the key to your github profile as per https://help.github.com/articles/adding-a-new-ssh-key-to-your-github-account/

  2. Modify the settings in IntelliJ under | VersionControl > GitHub

Tick 'Clone git repositories using ssh'

IntelliJ Settings Screenshot for Github

Choose 'Native' as 'SSH executable'

enter image description here

like image 28
tobig77 Avatar answered Oct 23 '22 17:10

tobig77


Steve Byrne is right about the changes to this procedure. As I do not have enough reputation to comment, I would like to add to his answer that I could only make this work with Github when inputing the SSH URL in the prompt for cloning a repo. You can get your repo's SSH URL by clicking on "Clone or Download" and then "Use SSH" on Github, like so:

enter image description here

like image 4
thenaturalist Avatar answered Oct 23 '22 17:10

thenaturalist


  • Open Git Bash and create a new ssh key using your GitHub email address like this:

    ssh-keygen -t rsa -b 4096 -C "[email protected]"

  • Then it asks you a file path for saving the key. You can simply accept the default by pressing Enter.

  • You then will be asked for a passphrase. Make sure you remember it as you may need it at the time you want to push your project's changes to GitHub.
  • Ensure your ssh agent is running. For that you can enter the following command

    eval $(ssh-agent -s)

  • Now add your SSH private key to the ssh-agent like this:

    ssh-add ~/.ssh/id_rsa

  • Now go to your GitHub profile and select setting->SSH and GPG keys. Select New SSH Key and after entering a title, copy your key using this command :

    clip < ~/.ssh/id_rsa.pub

  • Finally go to the Git setting of IntelijIDEA and select Built-in for SSH executable.

  • You can try to see if everything works fine by pushing your project to GitHub. You will be asked for the passphrase you entered when creating ssh key.

like image 4
abshar Avatar answered Oct 23 '22 18:10

abshar