简体   繁体   English

无法在Windows上克隆,但可以从Gitlab服务器在Linux上克隆

[英]Can't clone on windows but can clone on linux from Gitlab server

I am trying to clone a repository from a remote Gitlab server over SSH. 我正在尝试通过SSH从远程Gitlab服务器克隆存储库。 I am using Gitlab CE version 9.3.9 755bb71 and TortoiseGIT version 2.5.0 and git (for windows) version 2.14.0 我正在使用Gitlab CE version 9.3.9 755bb71TortoiseGIT version 2.5.0git (for windows) version 2.14.0

SSH Keys are installed correctly as I have tested the authentication using SSH密钥已正确安装,因为我已经使用

ssh -vT git@192.168.100.100 -i /path/to/.ssh/key

I get the following message for authentication success using the above key 使用以上密钥,我收到以下消息,表示身份验证成功

OpenSSH_7.5p1, OpenSSL 1.0.2k  26 Jan 2017
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to 192.168.100.100 [192.168.100.100] port 22.
debug1: Connection established.
debug1: identity file /path/to/.ssh/key type 1
debug1: key_load_public: No such file or directory
debug1: identity file /path/to/.ssh/key-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.5
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.6.1
debug1: match: OpenSSH_6.6.1 pat OpenSSH_6.6.1* compat 0x04000000
debug1: Authenticating to 192.168.100.100:22 as 'git'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256@libssh.org
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:fEztD+bNxKRs24poXJMlP0GBAP6Q1dZT80OhQAtDQJE
debug1: Host '192.168.100.100' is known and matches the ECDSA host key.
debug1: Found key in /path/to/.ssh/known_hosts:1
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /path/to/.ssh/key
debug1: Server accepts key: pkalg ssh-rsa blen 535
Enter passphrase for key '/path/to/.ssh/key':
debug1: Authentication succeeded (publickey).
Authenticated to 192.168.100.100 ([192.168.100.100]:22).
debug1: channel 0: new [client-session]
debug1: Requesting no-more-sessions@openssh.com
debug1: Entering interactive session.
debug1: pledge: network
debug1: Remote: Forced command.
debug1: Remote: Port forwarding disabled.
debug1: Remote: X11 forwarding disabled.
debug1: Remote: Agent forwarding disabled.
debug1: Remote: Pty allocation disabled.
debug1: Remote: Forced command.
debug1: Remote: Port forwarding disabled.
debug1: Remote: X11 forwarding disabled.
debug1: Remote: Agent forwarding disabled.
debug1: Remote: Pty allocation disabled.
Welcome to GitLab, John Doe!
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug1: client_input_channel_req: channel 0 rtype eow@openssh.com reply 0
debug1: channel 0: free: client-session, nchannels 1
Transferred: sent 3476, received 3264 bytes, in 2.2 seconds
Bytes per second: sent 1574.0, received 1478.0
debug1: Exit status 0

When I use TortoiseGit on windows to clone a repository I get the following error on the client 当我在Windows上使用TortoiseGit克隆存储库时,在客户端上出现以下错误

Cloning into 'C:\path\folder'...
GitLab: Disallowed command
fatal: Could not read from remote repository.

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

On the gitlab server, in the gitlab-shell.log I get the following warning message 在gitlab服务器上,在gitlab-shell.log我收到以下警告消息

WARN -- : gitlab-shell: Attempt to execute disallowed command <git upload-pack '/path/to/repo.git'> by user with key key-1.

But when I try git clone from another linux machine with a different SSH key it's successfull and I get the following info message in gitlab-shell.log on the gitlab server 但是,当我尝试使用另一台SSH密钥从另一台Linux机器上进行git clone成功时,我在gitlab服务器上的gitlab gitlab-shell.log收到以下信息消息

INFO -- : gitlab-shell: executing git command <gitaly-upload-pack  {"repository":{"path":"/very/long/path/to/repo.git"},"gl_id":"key-2"}> for user with key key-2.

I have spent more than 10 hours trying to debug everything and I am not sure what's the difference or where exactly is the problem. 我花了十多个小时来尝试调试所有内容,但我不确定有什么区别或问题到底出在哪里。 I have also tried adding the following in my local .gitconfig file for TortoiseGit but that doesn't change anything. 我也尝试将以下内容添加到TortoiseGit的本地.gitconfig文件中,但这没有任何改变。

[remote "origin"]
  uploadpack = git-upload-pack

Finally, cloning the same repository over HTTPS works fine, without any problem using a username / password. 最后,通过HTTPS克隆相同的存储库工作正常,而使用用户名/密码则没有任何问题。

Note: I just upgrade to Git 2.14.0 for Windows... and none of the ssh url are working: 注意:我只是升级到Windows的Git 2.14.0 ...而ssh网址都无法正常工作:

> git ls-remote
GitLab: Disallowed command
fatal: Could not read from remote repository.

(with origin being an ssh url) origin是ssh网址)

Another side effect: git-for-windows/git issue 1258 另一个副作用: git-for-windows / git问题1258

fatal: protocol error: bad line length character: Not

It looks as if BitBucket looks at argv[0] (typically git-upload-pack , with the regression git) to determine whether it is a permitted command. 好像BitBucket看着argv[0] (通常是git-upload-pack ,带有回归git)来确定它是否是允许的命令。

So I think it is by design that git is rejected while git-upload-pack is not. 因此,我认为这是设计使git被拒绝而git-upload-pack不被拒绝的原因。

Same kind on error on GitLab: gitlab-ce issue 36028 . 关于GitLab的错误的同类: gitlab-ce问题36028
The pending merge request explicitly restore git-xxx when it detects a git xxx command . 待处理的合并请求 在检测到git xxx命令时显式恢复git-xxx

See gitlab_shell.rb#parse_cmd(args) 参见gitlab_shell.rb#parse_cmd(args)

  def parse_cmd(args)
    # Handle Git for Windows 2.14 using "git upload-pack" instead of git-upload-pack
    if args.length == 3 && args.first == 'git'
      @command = "git-#{args[1]}"
      args = [@command, args.last]
    else
      @command = args.first
    end

At the Git for Windows side, a fix is in progress: see commit 0f33428 在Windows的Git端,一个修复程序正在进行中: 参见commit 0f33428

Revert "git_connect: prefer Git's builtins over dashed form" 还原“ git_connect:首选Git的内建函数而不是虚线形式”

It would appear that this change (which was intended to fix tests interacting with local repositories when git-upload-pack was not in the PATH ) regresses on SSH access. 似乎此更改(旨在修复当git-upload-pack不在PATH时与本地存储库交互的测试)在SSH访问中逐渐消失。

A Git for Windows 2.14.0(2) is in the work and was just released (2017-08-07T11:05:34Z UTC) 30 minutes ago at the time of this edit. 用于Windows 2.14.0(2)的Git正在开发中,并且在此编辑时的30分钟前刚刚发布(2017-08-07T11:05:34Z UTC)。


Original answer 原始答案

If key1 is the same as your /path/to/.ssh/key and does identify John Doe, that should mean John Doe does not have access to that repo ( as in here ). 如果key1与您的/path/to/.ssh/key相同,并且确实标识了John Doe,则这意味着John Doe无权访问该存储库( 如此处所示 )。
Check that key2 is associated with a different user. 检查key2是否与其他用户关联。

If both keys reference the same user, then it is more a local configuration issue (as in this answer ). 如果两个键都引用相同的用户,那么这将是一个本地配置问题(如本答案所示 )。 Check also that your TortoiseGit does use the same key as in your test: 还要检查您的TortoiseGit是否使用与测试中相同的密钥:

set "GIT_COMMAND_SSH=ssh -v"
# launch TortoiseGit from that CMD session

You will then see what TortoiseGit is using when cloning the repo with an ssh url. 然后,您将看到使用ssh url克隆存储库时正在使用的TortoiseGit。 You might need to define an .ssh/config file . 您可能需要定义一个.ssh/config文件

Both Bitbucket Server and Gogs are seeing similar problems. Bitbucket ServerGogs都遇到类似的问题。

It appears that something changed in git 2.14.0 (possibly only on Windows) that requires either an update to the products or a fix to git. 似乎在git 2.14.0中(可能仅在Windows上)发生了更改,需要对产品进行更新或对git进行修复。

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

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