git PHPStorm 密钥对设置以使用 gitlab

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25672123/
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-19 10:21:35  来源:igfitidea点击:

PHPStorm keypair setup to use gitlab

gitphpstormgitlabopenssh

提问by fefe

I just got a License for PhpStorm and I try to setup keypairs to can pull codes to Gitlab but I do not find where and how to make this? Where do I do this? The problem seems to be related that PhpStorm is not using root privileges.

我刚刚获得了 PhpStorm 的许可证,我尝试设置密钥对以将代码拉到 Gitlab,但我找不到在哪里以及如何制作它?我在哪里做这个?问题似乎与 PhpStorm 没有使用 root 权限有关。

回答by cbrendanprice

While I'm not entirely sure this is the most appropriate place to put this answer, I believe it is the most likely place others will end up at when facing issues trying to connect to GitLab via VCS for PHPStorm (or, really, any JetBrains IDE).

虽然我不完全确定这是放置这个答案的最合适的地方,但我相信这是其他人在尝试通过 VCS for PHPStorm(或者,实际上,任何 JetBrains)连接到 GitLab 遇到问题时最有可能的地方IDE)。

That being said, the issue I faced is very similar to the OP-- when running Git Bash, I had no issues at all connecting to Git Lab via SSH. However, when attempting a connection with PHPStorm's VCS via Git it would perpetually hang.

话虽如此,我面临的问题与 OP 非常相似——在运行 Git Bash 时,我通过 SSH 连接到 Git Lab 完全没有问题。但是,当尝试通过 Git 连接 PHPStorm 的 VCS 时,它会永久挂起。

To precursor, my own findings are secluded to those of you running JetBrain IDEs on Windows.

作为前兆,我自己的发现与那些在 Windows 上运行 JetBrain IDE 的人无关。



The solution is:

解决办法是:

  1. First you must (obviously) have an SSH key createdand registered for your GitLab user account.
  2. As @Spero.ShiroPettohas mentioned, PHPStorm does indeed utilize the standard $HOME/.ssh directory for SSH Keys. So:
    • Ensure your newly generated Key files are available from your home directory, inside the .ssh folder.
    • PHPStorm also uses the standard naming convention for these files, so for the sake of simplicity, keep these named as "id_rsa" and "id_rsa.pub".
  3. (OPTIONAL)It would be good practice to also create a config filefor your SSH keys. This will help in the event you need to have multiple key's down the line. If you're using a non standard SSH port, or if there are other non standard parameters associated with the connection to the server, this really is a must.
  4. Now, you're ready to open up PHPStorm but, before doing so, ensure you are running it as Administrator. This is necessary because when using VCS for Git, PHPStorm creates a batch file in your temp directory. This file must be writable for PHPStorm, and this is accomplished most simply by running the application as an Administrator.
  5. Finally, before attempting to test/clone the repo from your GitLab server, you'll need to set Git to use it's built-in SSH executable when accessing Git. So:
    • open up the settings for PHPStorm (File->Settings or Ctrl+Alt+S)
    • Expand the Version Control section in the Project Settings and select Git
    • Ensure that the SSH-Executable is set to "Built-in". (While you're here, you might as well ensure that the Git executable is also set correctly. You can hit the Test button to verify this)
  1. 首先,您必须(显然)为您的 GitLab 用户帐户创建注册SSH 密钥
  2. 正如@Spero.ShiroPetto所提到的,PHPStorm 确实使用标准的 $HOME/.ssh 目录作为 SSH 密钥。所以:
    • 确保您的新生成的密钥文件可从您的主目录.ssh 文件夹内获得。
    • PHPStorm 也对这些文件使用标准命名约定,因此为了简单起见,将它们命名为“id_rsa”和“id_rsa.pub”。
  3. (可选)为您的 SSH 密钥创建一个配置文件也是一种很好的做法。如果您需要多个键,这将有所帮助。如果您使用的是非标准 SSH 端口,或者如果有其他与服务器连接相关的非标准参数,这确实是必须的。
  4. 现在,您已准备好打开 PHPStorm,但在此之前,请确保您以管理员身份运行它。这是必要的,因为在将 VCS 用于 Git 时,PHPStorm 在您的临时目录中创建一个批处理文件。这个文件必须是 PHPStorm 的可写文件,最简单的方法是以管理员身份运行应用程序。
  5. 最后,在尝试从 GitLab 服务器测试/克隆存储库之前,您需要将 Git 设置为在访问 Git 时使用它的内置 SSH 可执行文件。所以:
    • 打开 PHPStorm 的设置(文件->设置或 Ctrl+Alt+S)
    • 展开 Project Settings 中的 Version Control 部分并选择 Git
    • 确保 SSH-Executable 设置为“内置”。(当你在这里时,你最好确保 Git 可执行文件也被正确设置。你可以点击“测试”按钮来验证这一点)

If like the OP and myself, you've been able to connect via Git Bash before, then at this point you should be able to connect and use VCS for your Git needs.

如果像 OP 和我自己一样,您之前已经能够通过 Git Bash 进行连接,那么此时您应该能够连接并使用 VCS 来满足您的 Git 需求。

回答by Razer

You have o create a pair of keys on the shell. Therefore follow these instructions. Then copy the content of the public key to your GitLab user account.

您可以在外壳上创建一对密钥。因此请遵循这些说明。然后将公钥的内容复制到您的 GitLab 用户帐户中。

回答by codemonkee

I've never used Netbeans, so not sure if you are adding your private key directly into your IDE or not, but PHPStorm uses standard Git/SSH settings.

我从未使用过 Netbeans,因此不确定您是否将私钥直接添加到 IDE 中,但 PHPStorm 使用标准的 Git/SSH 设置。

  • What OS are you using?
  • If Windows, when you installed Git (msysgit) did you choose OpenSSH or plink?
  • 你使用的是什么操作系统?
  • 如果是Windows,你在安装Git(msysgit)时是选择OpenSSH还是plink?

PHPStorm will utilize the standard $HOME/.sshor %userprofile%/.ssh- You can store a single id_rsa key here or if you use multiple keys you can add the configuration to %userprofile%/.ssh/config.

PHPStorm 将使用标准$HOME/.ssh%userprofile%/.ssh- 您可以在此处存储单个 id_rsa 密钥,或者如果您使用多个密钥,则可以将配置添加到%userprofile%/.ssh/config.

There is a bit of information in the PHPStorm help files - http://www.jetbrains.com/phpstorm/webhelp/using-git-integration.html#d598046e253

PHPStorm 帮助文件中有一些信息 - http://www.jetbrains.com/phpstorm/webhelp/using-git-integration.html#d598046e253

If you are using plinkon Windows, make sure you connect with PuTTYor plinkfirst so that you can accept the server's host key..

如果您plink在 Windows上使用,请确保先使用PuTTY或进行连接,plink以便您可以接受服务器的主机密钥。

plink [email protected]:group/repo.git
The server's host key is not cached in the registry. You
have no guarantee that the server is the computer you
think it is.
The server's rsa2 key fingerprint is:
ssh-rsa 2048 b6:03:0e:39:97:9e:d0:e7:24:ce:a3:77:3e:01:42:09
If you trust this host, enter "y" to add the key to
PuTTY's cache and carry on connecting.
If you want to carry on connecting just once, without
adding the key to the cache, enter "n".
If you do not trust this host, press Return to abandon the
connection.
Store key in cache? (y/n) y
Using username "git".
Server refused to allocate pty
Welcome to GitLab, User!

Depending on your setup, use ssh-agentor Pageant and add your key (ssh-addif using ssh-agent) so you are not prompted each time for your passphrase.

根据您的设置,使用ssh-agent或 Pageant 并添加您的密钥(ssh-add如果使用ssh-agent),这样就不会每次都提示您输入密码。

Your other alternative would be to connect over https and supply your credentials.

您的另一种选择是通过 https 连接并提供您的凭据。