简体   繁体   中英

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:

> 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:

> 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. It seems to work when I try to access github.com with ssh from PowerShell:

> 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?

When working in Eclipse in Windows, using the "Git Repositories" view it works fine to clone the same repo.

Previously I created new SSH keys in the PowerShell and copied the public one to GitHub, but with the same result.

My ~/.ssh/config file lookes like this:

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

I am using Git version:

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

Unfortunately I get no extra information from using the --verbose flag:

> 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-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? I would be so grateful for some help.

The problem was that my %HOME% environment variable was set to the wrong location. When I changed it back to C:\Users\<userid> it worked like charm. 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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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