使用私钥的 Android Studio git

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36860696/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 04:07:22  来源:igfitidea点击:

Android studio git using private key

gitandroid-studiosshprivate-key

提问by Goltsev Eugene

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!

A 有一个 git 仓库地址。
我还有一个 open-ssh 格式的私钥。

Android Studio 中的 git 是否可以使用它?
我试图搜索一些信息,但此时没有运气。

感谢您提供任何有用的信息!

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

编辑。我的步骤:
1. 我将我的私钥放在 .ssh 文件夹中(用户/用户)。
2. 在 Android Studio 中,我运行:文件 - 设置 - 版本控制 - Git 并输入 Git 可执行文件的路径。 3. 然后是 VCS - Checkout from vesrion control - Git。我把存储库地址放在那里。
在此处输入图片说明
在此处输入图片说明

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?

Android Studio 如何知道它应该使用我的私钥而不是标准的 id_rsa 文件?

采纳答案by Goltsev Eugene

Ok, finally got it working!

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

好的,终于可以运行了!

我所做的 - 切换到 .ssh 文件夹,然后将id_rsa密钥的内容(据我所知,这是 Android Studio 的默认 ssh 密钥)替换为我的ssh key.

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

仍然不知道方法,我如何将 Android Studio 指向我的ssh key.

回答by Mateusz

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

如何使用 Windows 上的 Android Studio 和 PuttyGen 来生成密钥 - 对于傻瓜:

  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 %USER%/.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.

  1. 使用 PuttyGen 将您的私钥导出到文件 Conversions>Export OpenSSHKey

  2. 在安装了 Android Studio 的 Windows 机器上,转到 %USER%/.ssh 目录。

  3. 将步骤 1 中导出的文件复制到此文件夹并将文件名更改为“id_rsa”。

  4. 在 Android Studio 菜单中,转到 VCS>Checkout from Version Control>Git。

  5. 粘贴 Git url(如其他回复中所述)并按“克隆”。

  6. 它应该要求您输入密钥文件的密码(如果使用)而不是 Git 的密码。

回答by davisjp

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.

正如@CodeWizard 所提到的,Android Studio 正在从操作系统获取密钥,因此使用 ssh-add 将密钥添加到 ssh-agent 对我有用。

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

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

回答by Tudor

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

再补充一个答案。Android Studio 带有内置的 SSH 客户端。您必须从内置切换到本机。这将使用 .ssh 文件夹中的密钥

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

文件 -> 设置 -> 版本控制 -> Git -> SSH 可执行文件 -> 本机

回答by CodeWizard

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.

您只需将密钥添加到您的服务器。
Android Studio 使用的是操作系统 git 而不是 Eclipse 中的 Egit,后者有自己的 git 实现。

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.

无需进行特殊配置。
检查一切是否在 bash/终端上运行,它也可以在 Android Studio 中运行。



What to do if its not working?

What to do if its not working?

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

如果您无法从 Studio 访问您的存储库,请使用以下格式作为您的连接 url

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

This will use a direct connection using ssh keys.

这将使用使用 ssh 密钥的直接连接。