无法从 windows/phpstorm 推送到 git

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

Cannot push to git from windows/phpstorm

git

提问by onok

My repository is on Bitbucket. I have a Ubuntu machine that I use as a development server (which hosts a local copy of all my code, apache, php, git etc). The actual development is done on a Windows machine in the same LAN. I use a Samba share to access the files on the server directly. I use PHPStorm as my IDE. I installed git on the Windows machine as well, in order to use git integration in PHPStorm. And it works: I can read the repository history and commit new changes withouth problem.

我的存储库在 Bitbucket 上。我有一台 Ubuntu 机器,用作开发服务器(它托管我所有代码、apache、php、git 等的本地副本)。实际开发是在同一局域网内的一台 Windows 机器上完成的。我使用 Samba 共享直接访问服务器上的文件。我使用 PHPStorm 作为我的 IDE。我也在 Windows 机器上安装了 git,以便在 PHPStorm 中使用 git 集成。它有效:我可以阅读存储库历史记录并提交新的更改而不会出现问题。

But now I want to push (to bitbucket) from PHPStorm as well. And that is what fails.

但是现在我也想从 PHPStorm 推送(到 bitbucket)。这就是失败的原因。

Right now, I need to login to my Ubuntu server to push code from there. But I'd like to be able to psuh from PHPStorm. It has probably to do with ssh-keys I need to integrate, but I don't know how. PHPStorm tells me the following:

现在,我需要登录到我的 Ubuntu 服务器才能从那里推送代码。但我希望能够从 PHPStorm 进行 psuh。它可能与我需要集成的 ssh 密钥有关,但我不知道如何集成。PHPStorm 告诉我以下内容:

19:22:10.873: git push --progress origin master:master
java.io.IOException: Authentication failed: 
    at org.jetbrains.git4idea.ssh.SSHMain.authenticate(SSHMain.java:283)
    at org.jetbrains.git4idea.ssh.SSHMain.start(SSHMain.java:157)
    at org.jetbrains.git4idea.ssh.SSHMain.main(SSHMain.java:137)
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.

I already created a SSH key pair and put the public key on Bitbucket. I just don't know where to go from here.

我已经创建了一个 SSH 密钥对并将公钥放在 Bitbucket 上。我只是不知道从这里去哪里。

回答by Dean Cirielli

If your git commands work from the commandline, but not from inside WebStorm, you could try switching your WebStorm configuration to use "Native" instead of the "Built-in" SSH executable.

如果您的 git 命令从命令行运行,而不是从 WebStorm 内部运行,您可以尝试将 WebStorm 配置切换为使用“本”而不是“内置”SSH 可执行文件。

To do this, navigate the menus for Files -> Settings -> Version Control -> Gitand then change the SSH executabledropdown setting to "Native."

为此,请导航Files -> Settings -> Version Control -> Git的菜单,然后将SSH 可执行文件下拉设置更改为“ Native ”

回答by VonC

The PhpStorm git Integrationman page does mention:

PhpStorm git的整合手册页确实提到:

  • ssh keys are generated outside PhpStorm. You can follow the instructions from http://inchoo.net/tools/how-to-generate-ssh-keys-for-git-authorization/or look for other guidelines.
  • Store the ssh keys in the home_directory \.ssh\folder. The location of the home directory is defined through environmental variables:
    • $HOMEfor Unix-like operating systems.
    • %userprofile%for the Microsoft Windows operating system.
  • Make sure, the keys are stored in files with correct names:
    • id_rsafor the private key.
    • id_rsa.pubfor the public key.
  • ssh 密钥是在 PhpStorm 之外生成的。您可以按照http://inchoo.net/tools/how-to-generate-ssh-keys-for-git-authorization/ 中的说明进行操作或查找其他指南。
  • 将 ssh 密钥存储在 home_directory\.ssh\文件夹中。主目录的位置是通过环境变量定义的:
    • $HOME适用于类 Unix 操作系统。
    • %userprofile%适用于 Microsoft Windows 操作系统。
  • 确保密钥存储在名称正确的文件中:
    • id_rsa对于私钥。
    • id_rsa.pub为公钥。

回答by codemonkee

If you are using the native SSH executable option in PhpStorm & linked to plink.exeprovided with PuTTY, you will need to connect to the host server at least once to accept the server's host key. Once the key is cached you can then add your Private key into pageant.exe

如果您在 PhpStorm 中使用本机 SSH 可执行选项并链接到plink.exePuTTY,您将需要至少连接到主机服务器一次以接受服务器的主机密钥。一旦密钥被缓存,您就可以将您的私钥添加到pageant.exe

plink.exe [email protected]
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 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48
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
Hi username! You've successfully authenticated, but GitHub does not provide shell access.

回答by Raja Amer Khan

I had this issue. My ssh keys were perfectly fine as I was using them with Git Bash (Windows).

我有这个问题。我的 ssh 密钥非常好,因为我将它们与 Git Bash (Windows) 一起使用。

I deleted known_hosts from C:\Users\Your User Name\.sshfolder and PHPStorm created it on its own and it started working.

我从C:\Users\Your User Name\.ssh文件夹中删除了 known_hosts ,PHPStorm 自己创建了它并开始工作。

On my another project, it was giving following error:

在我的另一个项目中,它给出了以下错误:

java.io.IOException: There was a problem while connecting to 158.xxx.xxx.xxx::22
    at com.trilead.ssh2.Connection.connect(Connection.java:791)
    at com.trilead.ssh2.Connection.connect(Connection.java:577)
    at org.jetbrains.git4idea.ssh.SSHMain.start(SSHMain.java:171)
    at org.jetbrains.git4idea.ssh.SSHMain.main(SSHMain.java:137)
Caused by: java.net.UnknownHostException: 158.xxx.xxx.xxx:: invalid IPv6 address
    at java.net.InetAddress.getAllByName(InetAddress.java:1169)
    at java.net.InetAddress.getAllByName(InetAddress.java:1126)
    at java.net.InetAddress.getByName(InetAddress.java:1076)
    at com.trilead.ssh2.transport.TransportManager.createInetAddress(TransportManager.java:165)
    at com.trilead.ssh2.transport.TransportManager.establishConnection(TransportManager.java:340)
    at com.trilead.ssh2.transport.TransportManager.initialize(TransportManager.java:449)
    at com.trilead.ssh2.Connection.connect(Connection.java:731)
    ... 3 more
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.

And it turned out the remote url of my GIT project was set wrong:

结果我的 GIT 项目的远程 url 设置错误:

ssh://myuser@myip:/home/user/myrepo

should be:

应该:

myuser@myip:/home/user/myrepo