15

A have an address of git repository.
Also I have a private key in open-ssh format.

Is it possible for git in Android Studio to use it?
I tried to search some info, but no luck at this time.

Thanks for any useful information!

Edit. My steps:
1. I put my private key in .ssh folder (Users/user).
2. In Android studio I run: File - Settings - Version Control - Git and put the path to Git executable.
enter image description here
3. Then VCS - Checkout from vesrion control - Git. I put repository address there. enter image description here

If I continue here, there is:
enter image description here

But I don't have username and password, only key.
If I try:
enter image description here
got the following:
enter image description here

And how Android Studio would know, that it should take my private key instead of standard id_rsa file?

Goltsev Eugene
  • 3,325
  • 6
  • 25
  • 48

5 Answers5

18

As @CodeWizard mentioned, Android Studio was getting the key from the OS so using ssh-add to add the keys to the ssh-agent worked for me.

ssh-add ~/.ssh/id_rsa

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

davisjp
  • 730
  • 1
  • 11
  • 24
  • 1
    This answer only works on Linux and MacOS type systems. Windows does not have built-in ssh-agent support, and Android Studio does not work with PuTTY's Pageant authentication agent. – simpleuser Jun 13 '22 at 03:59
15

Ok, finally got it working!

What I did - switched to .ssh folder, then replaced contents of id_rsa key (as I understand, this is default ssh key of Android Studio) with contents of my ssh key.

Still don't know the way, how can I point Android Studio to my ssh key, but in such way it works.

Goltsev Eugene
  • 3,325
  • 6
  • 25
  • 48
10

How to get it working using Android Studio on Windows and PuttyGen for generating the key - for dummies:

  1. Export your private key using PuttyGen to file Conversions>Export OpenSSHKey

  2. On the Windows machine where you have Android Studio installed go to your %USERPROFILE%/.ssh directory.

  3. Copy the file exported in step 1 to this folder and change filename to "id_rsa".

  4. In Android Studio menu go to VCS>Checkout from Version Control>Git.

  5. Paste Git url (as mentioned in other replies) and press "Clone".

  6. It should ask you for password for the key file (if used) instead of a password for Git.

simpleuser
  • 1,617
  • 25
  • 36
Mateusz
  • 101
  • 1
  • 5
2

To add one more answer. Android Studio comes with Built in SSH client. You must switch from the built in to native. This will use the keys from .ssh folder

File -> Settings -> Version Control -> Git -> SSH Executable -> Native

Tudor
  • 1,510
  • 1
  • 18
  • 17
  • 1
    This actually allows using a GPG provided SSH key as well. This is especially handy if you are using a Yubikey hosted GPG key, since you have to unlock the GPG key using a PIN, which is then cached for a configurable period. – dragon788 Mar 13 '19 at 20:15
  • 3
    Be adviced that the configuration options for which SSH executable to use has been removed, and the native client is used now by default. – Hrafn Mar 10 '21 at 12:19
0

You simply need to add the key to your server.
Android studio is using the OS git and not Egit like in Eclipse which has its own git implementation.

No special configuration need to be done.
check that all is working from bash/terminal and it will work in the Android Studio as well.


What to do if its not working?

If you cant access your repository from the Studio use the following format as your connections url

:ssh:git@<server ip>:<git repository path>

This will use a direct connection using ssh keys.

Jakuje
  • 24,773
  • 12
  • 69
  • 75
CodeWizard
  • 128,036
  • 21
  • 144
  • 167