繁体   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