无法通过 HTTPS 在 Linux 上克隆 github 存储库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12538130/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can't clone a github repo on Linux via HTTPS
提问by Yarin
I'm trying to do a simple git clone https://github.com/org/project.git
on a CentOS box but get:
我正在尝试git clone https://github.com/org/project.git
在 CentOS 机器上做一个简单的事情,但得到:
error: The requested URL returned error: 401 while accessing https://github.com/org/project.git/info/refs
fatal: HTTP request failed
错误:请求的 URL 在访问https://github.com/org/project.git/info/refs 时返回错误:401
致命:HTTP 请求失败
It never prompts me for my username/password, just fails.
它从不提示我输入用户名/密码,只是失败了。
I can make the exact same call on my Mac no problem- what am I missing?
我可以在 Mac 上拨打完全相同的电话,没问题——我错过了什么?
采纳答案by Yarin
The answer was simple but not obvious:
答案很简单,但并不明显:
Instead of:
代替:
git clone https://github.com/org/project.git
do:
做:
git clone https://[email protected]/org/project.git
or (insecure)
或(不安全)
git clone https://username:[email protected]/org/project.git
(Note that in the later case, your password will may be visible by other users on your machine by running ps u -u $you
and will appear cleartext in your shell's history by default)
(请注意,在后一种情况下,您的计算机上的其他用户可能会通过运行看到您的密码,ps u -u $you
并且默认情况下将在您的 shell 历史记录中以明文形式显示)
All 3 ways work on my Mac, but only the last 2 worked on the remote Linux box. (Thinking back on this, it's probably because I had a global git usernameset up on my Mac, whereas on the remote box I did not? That might have been the case, but the lack of prompt for a username tripped me up... )
所有 3 种方式都适用于我的 Mac,但只有最后两种方式适用于远程 Linux 机器。(回想一下,这可能是因为我在 Mac 上设置了全局 git 用户名,而在远程机器上我没有?可能是这种情况,但是没有输入用户名的提示让我感到困惑.. .)
Haven't seen this documented anywhere, so here it is.
没有在任何地方看到这个记录,所以在这里。
回答by BenDundee
This is the dumbest answer to this question, but check the status of GitHub. This one got me :)
这是这个问题最愚蠢的答案,但请检查 GitHub 的状态。这个让我:)
回答by Chu-Siang Lai
You can manual disable ssl verfiy, and try again. :)
您可以手动禁用 ssl 验证,然后重试。:)
git config --global http.sslverify false
回答by JERC
回答by Rob Watts
As JERC said, make sure you have an updated version of git. If you are only using the default settings, when you try to install git you will get version 1.7.1. Other than manually downloading and installing the latest version of get, you can also accomplish this by adding a new repository to yum.
正如 JERC 所说,确保你有一个更新版本的 git。如果您只使用默认设置,当您尝试安装 git 时,您将获得 1.7.1 版本。除了手动下载和安装最新版本的 get 之外,您还可以通过向 yum 添加新存储库来完成此操作。
From tecadmin.net:
Download and install the rpmforge repository:
下载并安装 rpmforge 存储库:
# use this for 64-bit
rpm -i 'http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm'
# use this for 32-bit
rpm -i 'http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.i686.rpm'
# then run this in either case
rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt
Then you need to enable the rpmforge-extras. Edit /etc/yum.repos.d/rpmforge.repo
and change enabled = 0
to enabled = 1
under [rpmforge-extras]
. The file looks like this:
然后你需要启用 rpmforge-extras。编辑/etc/yum.repos.d/rpmforge.repo
并更改enabled = 0
为enabled = 1
下[rpmforge-extras]
。该文件如下所示:
### Name: RPMforge RPM Repository for RHEL 6 - dag
### URL: http://rpmforge.net/
[rpmforge]
name = RHEL $releasever - RPMforge.net - dag
baseurl = http://apt.sw.be/redhat/el6/en/$basearch/rpmforge
mirrorlist = http://mirrorlist.repoforge.org/el6/mirrors-rpmforge
#mirrorlist = file:///etc/yum.repos.d/mirrors-rpmforge
enabled = 1
protect = 0
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rpmforge-dag
gpgcheck = 1
[rpmforge-extras]
name = RHEL $releasever - RPMforge.net - extras
baseurl = http://apt.sw.be/redhat/el6/en/$basearch/extras
mirrorlist = http://mirrorlist.repoforge.org/el6/mirrors-rpmforge-extras
#mirrorlist = file:///etc/yum.repos.d/mirrors-rpmforge-extras
enabled = 0 ####### CHANGE THIS LINE TO "enabled = 1" #############
protect = 0
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rpmforge-dag
gpgcheck = 1
[rpmforge-testing]
name = RHEL $releasever - RPMforge.net - testing
baseurl = http://apt.sw.be/redhat/el6/en/$basearch/testing
mirrorlist = http://mirrorlist.repoforge.org/el6/mirrors-rpmforge-testing
#mirrorlist = file:///etc/yum.repos.d/mirrors-rpmforge-testing
enabled = 0
protect = 0
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rpmforge-dag
gpgcheck = 1
Once you've done this, then you can update git with
完成此操作后,您可以使用以下命令更新 git
yum update git
I'm not sure why, but they then suggest disabling rpmforge-extras (change back to enabled = 0
) and then running yum clean all
.
我不确定为什么,但他们建议禁用 rpmforge-extras(改回enabled = 0
),然后运行yum clean all
.
Most likely you'll need to use sudo
for these commands.
您很可能需要使用sudo
这些命令。
回答by Heine N?rby
I was able to get a git 1.7.1 to work after quite some time.
一段时间后,我能够让 git 1.7.1 工作。
First, I had to do disable SSL just so I could pull:
首先,我必须禁用 SSL 才能拉取:
git config --global http.sslverify false
Then I could clone
然后我可以克隆
git clone https://github.com/USERNAME/PROJECTNAME.git
Then after adding and committing i was UNABLE to push back. So i did
然后在添加并提交后,我无法推回。所以我做了
git remote -v
origin https://github.com/USERNAME/PROJECTNAME.git (fetch)
origin https://github.com/USERNAME/PROJECTNAME.git (push)
to see the pull and push adresses:
查看拉取和推送地址:
These must be modified with USERNAME@
这些必须用 USERNAME@ 修改
git remote set-url origin https://[email protected]/USERNAME/PROJECTNAME.git
It will still prompt you for a password, which you could add with
它仍然会提示您输入密码,您可以添加
USERNAME:PASSWORD@github.....
But dont do that, as you save your password in cleartext for easy theft.
但是不要这样做,因为您以明文形式保存密码以方便盗窃。
I had to do this combination since I could not get SSH to work due to firewall limitations.
由于防火墙限制,我无法使 SSH 正常工作,因此我不得不进行这种组合。
回答by Senthil Kumar Sekar
I had the same problem and error. In my case it was the https_proxy not set. Setting the https_proxy environment variable fixed the issue.
我有同样的问题和错误。就我而言,它是 https_proxy 未设置。设置 https_proxy 环境变量修复了该问题。
$ export https_proxy=https://<porxy_addres>:<proxy_port>
Example:
例子:
$ export https_proxy=https://my.proxy.company.com:8000
Hope this help somebody.
希望这对某人有帮助。
回答by Andrius
I had to specify user name to work on 1.7.1 git version:
我必须指定用户名才能在 1.7.1 git 版本上工作:
git remote set-url origin https://[email protected]/org/project.git
回答by Warrren Liu
I met the same problem, the error message and OS info are as follows
我遇到了同样的问题,错误信息和操作系统信息如下
OS info:
操作系统信息:
CentOS release 6.5 (Final)
Linux 192-168-30-213 2.6.32-431.el6.x86_64 #1 SMP Fri Nov 22 03:15:09 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
CentOS 6.5 版(最终版)
Linux 192-168-30-213 2.6.32-431.el6.x86_64 #1 SMP Fri Nov 22 03:15:09 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
error info:
错误信息:
Initialized empty Git repository in /home/techops/pyenv/.git/ Password: error: while accessing https://[email protected]/pyenv/pyenv.git/info/refs
fatal: HTTP request failed
在 /home/techops/pyenv/.git/ 中初始化空 Git 存储库 密码:错误:访问https://[email protected]/pyenv/pyenv.git/info/refs
致命:HTTP 请求失败
git & curl version info
git & curl 版本信息
git info :git version 1.7.1
curl 7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.14.0.0 zlib/1.2.3 libidn/1.18 libssh2/1.4.2 Protocols: tftp ftp telnet dict ldap ldaps http file https ftps scp sftp Features: GSS-Negotiate IDN IPv6 Largefile NTLM SSL libz
git 信息:git 版本 1.7.1
curl 7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.14.0.0 zlib/1.2.3 libidn/1.18 libssh2/1.4.2 协议:tftp ftp telnet dict ldap ldaps cp 文件 https特性:GSS-Negotiate IDN IPv6 Largefile NTLM SSL libz
debugging
调试
$ curl --verbose https://github.com
- About to connect() to github.com port 443 (#0)
- Trying 13.229.188.59... connected
- Connected to github.com (13.229.188.59) port 443 (#0)
- Initializing NSS with certpath: sql:/etc/pki/nssdb
- CAfile: /etc/pki/tls/certs/ca-bundle.crt CApath: none
- NSS error -12190
Error in TLS handshake, trying SSLv3... GET / HTTP/1.1 User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.14.0.0 zlib/1.2.3 libidn/1.18 libssh2/1.4.2 Host: github.com Accept: /
Connection died, retrying a fresh connect
- Closing connection #0
- Issue another request to this URL: 'https://github.com'
- About to connect() to github.com port 443 (#0)
- Trying 13.229.188.59... connected
- Connected to github.com (13.229.188.59) port 443 (#0)
- TLS disabled due to previous handshake failure
- CAfile: /etc/pki/tls/certs/ca-bundle.crt CApath: none
- NSS error -12286
- Closing connection #0
- SSL connect error curl: (35) SSL connect error
$ curl --verbose https://github.com
- 即将 connect() 到 github.com 端口 443 (#0)
- 正在尝试 13.229.188.59... 已连接
- 连接到 github.com (13.229.188.59) 端口 443 (#0)
- 使用 certpath 初始化 NSS:sql:/etc/pki/nssdb
- CAfile:/etc/pki/tls/certs/ca-bundle.crt CApath:无
- NSS 错误 -12190
TLS 握手错误,尝试 SSLv3... GET / HTTP/1.1 User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.14.0.0 zlib/1.2.3 libidn/ 1.18 libssh2/1.4.2 主机:github.com 接受:/
连接已死,正在重试新的连接
- 关闭连接#0
- 向此 URL 发出另一个请求:' https://github.com'
- 即将 connect() 到 github.com 端口 443 (#0)
- 正在尝试 13.229.188.59... 已连接
- 连接到 github.com (13.229.188.59) 端口 443 (#0)
- 由于之前的握手失败,TLS 被禁用
- CAfile:/etc/pki/tls/certs/ca-bundle.crt CApath:无
- NSS 错误 -12286
- 关闭连接#0
- SSL 连接错误卷曲:(35) SSL 连接错误
after upgrading curl , libcurl and nss , git clone works fine again, so here it is. the update command is as follows
升级 curl 、 libcurl 和 nss 后, git clone 再次正常工作,所以就在这里。更新命令如下
sudo yum update -y nss curl libcurl
须藤 yum 更新 -y nss curl libcurl