简体   繁体   English

Git ssh 的克隆在 Linux 中有效,但在 Windows 中无效 PowerShell

[英]Git clone with ssh works in Linux but not in Windows PowerShell

I have a repo at GitHub. When cloning it in Linux using ssh it works fine:我在 GitHub 有一个回购协议。当使用 ssh 在 Linux 中克隆它时,它工作正常:

> git clone git@github.com:henrikppersson74/frokenjennnie.git                                                  
Cloning into 'frokenjennnie'...
Enter passphrase for key '/home/----/.ssh/id_rsa':
.
.
Reinitialized existing Git repository in /home/* 

When doing the same thing in Windows PowerShell it doesn't work:在 Windows PowerShell 中做同样的事情时,它不起作用:

> git clone git@github.com:henrikppersson74/frokenjennnie.git
Cloning into 'frokenjennnie'...
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.

I have copied my private and public SSH keys from Linux to my Windows machine and they are stored in my ~/.ssh/ as id_rsa and id_rsa.pub.我已将我的私人和公共 SSH 密钥从 Linux 复制到我的 Windows 机器,它们作为 id_rsa 和 id_rsa.pub 存储在我的 ~/.ssh/ 中。 It seems to work when I try to access github.com with ssh from PowerShell:当我尝试从 PowerShell 访问 github.com 和 ssh 时,它似乎有效:

> ssh git@github.com
Enter passphrase for key 'C:\Users\-----/\.ssh\id_rsa':
PTY allocation request failed on channel 0
Hi henrikppersson74! You've successfully authenticated, but GitHub does not provide shell access.
Connection to github.com closed.

This is the same answer I get when doing this in Linux. I guess this means the my SSH-key par is ok?这与我在 Linux 中执行此操作时得到的答案相同。我想这意味着我的 SSH 密钥 par 没问题?

When working in Eclipse in Windows, using the "Git Repositories" view it works fine to clone the same repo.在 Windows 中的 Eclipse 工作时,使用“Git 存储库”视图可以很好地克隆相同的存储库。

Previously I created new SSH keys in the PowerShell and copied the public one to GitHub, but with the same result.之前我在 PowerShell 中创建了新的 SSH 密钥,并将公共密钥复制到 GitHub,但结果相同。

My ~/.ssh/config file lookes like this:我的~/.ssh/config文件如下所示:

Host github.com
    HostName github.com
    IdentityFile ~\.ssh\id_rsa
    User git
    ForwardAgent yes

I am using Git version:我使用的是 Git 版本:

> git --version
git version 2.28.0.windows.1

Unfortunately I get no extra information from using the --verbose flag:不幸的是,我没有从使用 --verbose 标志中得到额外的信息:

> git clone git@github.com:henrikppersson74/frokenjennnie.git --verbose
Cloning into 'frokenjennnie'...
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

It doesn't help to add the key to the ssh-agent:将密钥添加到 ssh-agent 无济于事:

> ssh-add C:\Users\-----\.ssh\id_rsa
Enter passphrase for C:\Users\-----\.ssh\id_rsa:
Identity added: C:\Users\------\.ssh\id_rsa (C:\Users\-----\.ssh\id_rsa)
> git clone git@github.com:henrikppersson74/frokenjennnie.git --verbose
Cloning into 'frokenjennnie'...
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Could my old keys be cashed somewhere?我的旧钥匙可以在某个地方兑现吗?

Does anyone have any idea about why I am not able to clone my repo in Windows PowerShell?有谁知道为什么我无法在 Windows PowerShell 中克隆我的回购协议? I would be so grateful for some help.如果能提供一些帮助,我将不胜感激。

The problem was that my %HOME% environment variable was set to the wrong location.问题是我的%HOME%环境变量设置到了错误的位置。 When I changed it back to C:\Users\<userid> it worked like charm.当我将其改回C:\Users\<userid>时,它的效果非常好。 Apparently SSH first looks for a key in %HOME%\.ssh\ , then for en entry in %HOME%\.ssh\config\ and last it uses the keys added to the ssh-agent .显然 SSH 首先在%HOME%\.ssh\中查找密钥,然后在%HOME%\.ssh\config\中查找条目,最后它使用添加到ssh-agent的密钥。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM