简体   繁体   中英

Why git clone works only in Powershell running as administrator?

I configure ssh key for my Gitlab account and want to git clone my repo, but cloning works only in Powershell running as administrator.

The command below works the same in both cases (with admin rights and without):

ssh -T git@my.gitlab.host.com

The output is: Welcome to GitLab, @username!

How I can make to work git clone without running Powershell as administrator?


Update 1 :
whoami output also the same for both cases (with admin rights and without)

Update 2 :
git clone command error:

git@my.gitlab.host.com: Permission denied (publickey). fatal: Could not read from remote repository.

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

Update 3 :
git push command fails with the same error. Problem with access to private ssh key located in ~/.ssh/id_rsa ?

Update 4 :
I set the default ssh command for git ( ssh -Tv ) as VonC suggested, but with this command:
git config --global core.sshCommand "ssh -Tv" (setting the GIT_SSH_COMMAND was not worked for me)
First 19 lines output for git pull command (no admin):

OpenSSH_8.8p1, OpenSSL 1.1.1m  14 Dec 2021
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to my.gitlab.host.com [my.gitlab.host.ip] port 22.
debug1: Connection established.
debug1: identity file /t/.ssh/id_rsa type -1
debug1: identity file /t/.ssh/id_rsa-cert type -1
debug1: identity file /t/.ssh/id_dsa type -1
debug1: identity file /t/.ssh/id_dsa-cert type -1
debug1: identity file /t/.ssh/id_ecdsa type -1
debug1: identity file /t/.ssh/id_ecdsa-cert type -1
debug1: identity file /t/.ssh/id_ecdsa_sk type -1
debug1: identity file /t/.ssh/id_ecdsa_sk-cert type -1
debug1: identity file /t/.ssh/id_ed25519 type -1
debug1: identity file /t/.ssh/id_ed25519-cert type -1
debug1: identity file /t/.ssh/id_ed25519_sk type -1
debug1: identity file /t/.ssh/id_ed25519_sk-cert type -1
debug1: identity file /t/.ssh/id_xmss type -1
debug1: identity file /t/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.8

First 9 lines output for git pull command (admin):

OpenSSH_8.8p1, OpenSSL 1.1.1m  14 Dec 2021
debug1: Reading configuration data /c/Users/my_user/.ssh/config
debug1: /c/Users/my_user/.ssh/config line 1: Applying options for my.gitlab.host.com
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to my.gitlab.host.com [my.gitlab.host.ip] port 22.
debug1: Connection established.
debug1: identity file C:/Users/my_user/.ssh/id_rsa type 0
debug1: identity file C:/Users/my_user/.ssh/id_rsa-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.8

So it looks like in no-admin mode it even do not try to find keys/configs in right location. Any ideas of this behavior?

In both instances (admin or no admin), set first:

set "GIT_SSH_COMMAND=ssh -Tv"

That way, you will see which key is accessed (from which folder), and you can compare both session.


It looks like in no-admin mode it even do not try to find keys/configs in right location.

What it does look like is, in no-admin mode, there is an environment variable HOME set to T:\ or /t .
Type set HOME in a CMD to confirm.

Setting that variable to %USERPROFILE% would mean using the right path.

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