簡體   English   中英

為什么 git clone 只能在以管理員身份運行的 Powershell 中工作?

[英]Why git clone works only in Powershell running as administrator?

我為我的Gitlab帳戶配置了ssh key並希望git clone我的 repo,但克隆僅在以管理員身份運行的Powershell中有效。

以下命令在兩種情況下的工作方式相同(有管理員權限和沒有管理員權限):

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

輸出是: Welcome to GitLab, @username!

如何在不以管理員身份運行Powershell的情況下使git clone工作?


更新 1
兩種情況下whoami的輸出也相同(有管理員權限和沒有管理員權限)

更新 2
git clone命令錯誤:

git@my.gitlab.host.com:權限被拒絕(公鑰)。 致命:無法從遠程存儲庫中讀取。

請確保您具有正確的訪問權限並且存儲庫存在。

更新 3
git push命令失敗並出現同樣的錯誤。 訪問位於~/.ssh/id_rsa中的私有ssh key有問題嗎?

更新 4
我按照VonC的建議為git ( ssh -Tv ) 設置了默認ssh命令,但是使用以下命令:
git config --global core.sshCommand "ssh -Tv" (設置GIT_SSH_COMMAND對我不起作用)
git pull命令的前 19 行輸出(無管理員):

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

git pull命令(管理員)的前 9 行輸出:

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

所以看起來在無管理員模式下它甚至不會嘗試在正確的位置找到密鑰/配置。 對這種行為有任何想法嗎?

在這兩種情況下(管理員或無管理員),首先設置:

set "GIT_SSH_COMMAND=ssh -Tv"

這樣,您將看到訪問了哪個密鑰(從哪個文件夾),並且可以比較兩個會話。


看起來在無管理員模式下,它甚至不會嘗試在正確的位置找到密鑰/配置。

它的樣子是,在無管理員模式下,有一個環境變量HOME設置為T:\/t
在 CMD 中鍵入set HOME進行確認。

將該變量設置為%USERPROFILE%意味着使用正確的路徑。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM