在尝试访问 HTTPS url 时,如何使用 cURL 处理证书?
我使用curl 收到以下错误:
curl: (77) error setting certificate verify locations: CAfile: /etc/ssl/certs/ca-certificates.crt CApath: none
如何设置此证书验证位置?
I am getting the following error using curl:
curl: (77) error setting certificate verify locations: CAfile: /etc/ssl/certs/ca-certificates.crt CApath: none
How do I set this certificate verify locations?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(26)
我也有这个问题。我的问题是这个文件:
默认情况下只是一个空文件。因此,即使它存在,您仍然会收到错误,因为它不包含任何证书。您可以像这样生成它们:
https:/ /github.com/msys2/MSYS2-packages/blob/master/ca-certificates/ca-certificates.install
I had this problem as well. My issue was this file:
is by default just an empty file. So even if it exists, you'll still get the error as it doesn't contain any certificates. You can generate them like this:
https://github.com/msys2/MSYS2-packages/blob/master/ca-certificates/ca-certificates.install
就我而言(在 Mac 上),我有一个
/etc/ssl/cert_new.pem
而不是默认的证书文件名/etc/ssl/cert.pem
。因此,我运行 sudo cp cert_new.pem cert.pem 并修复了所有 ssl 问题。In my case (on Mac) I had a
/etc/ssl/cert_new.pem
instead of the default cert filename/etc/ssl/cert.pem
. So I runsudo cp cert_new.pem cert.pem
and all the ssl issues fixed.就我而言,这是一个权限问题
尝试
In my case, it was a permission issue
try
我还安装了最新版本的 ca-certificates,但仍然收到错误:
问题是curl 期望证书位于路径
/etc/pki/tls/certs/ca-bundle.crt 但找不到它,因为它位于路径
/etc/ssl/certs/ca-certificates.crt
。通过运行将我的证书复制到预期目的地
对我有用。如果目标目的地不存在,则需要通过运行“
如果需要,修改上述命令以使目标文件名与curl期望的路径匹配”来创建文件夹,即替换
/etc/pki/tls/certs /ca-bundle.crt
,其路径位于错误消息中的“CAfile:”之后。I also had the newest version of ca-certificates installed but was still getting the error:
The issue was that curl expected the certificate to be at the path
/etc/pki/tls/certs/ca-bundle.crt
but could not find it because it was at the path/etc/ssl/certs/ca-certificates.crt
.Copying my certificate to the expected destination by running
worked for me. You will need to create folders for the target destination if they do not exist by running
If needed, modify the above command to make the destination file name match the path expected by curl, i.e. replace
/etc/pki/tls/certs/ca-bundle.crt
with the path following "CAfile:" in your error message.此错误与缺少软件包有关:
ca-certificates
。安装它。在 Ubuntu Linux(和类似发行版)中:
在 CygWin 中,通过 Apt-Cyg
在 Arch Linux (Raspberry Pi) 中)
文档告诉:
如下所示:Debian ——squeeze 中软件包 ca-certificates 的详细信息
This error is related to a missing package:
ca-certificates
. Install it.In Ubuntu Linux (and similar distro):
In CygWin via Apt-Cyg
In Arch Linux (Raspberry Pi)
The documentation tells:
As seen at: Debian -- Details of package ca-certificates in squeeze
将其放入您的
.bashrc
(请参阅罗伯特的评论)
Put this into your
.bashrc
(see comment from Robert)
创建文件
~/.curlrc
,内容如下
Create a file
~/.curlrc
with the following contentas follows
解决该错误的最快方法是在curl 请求中的某处添加 -k 选项。该选项“允许在没有证书的情况下连接到 SSL 引用”。 (来自curl --help)
请注意,这可能意味着您没有与您认为的端点对话,因为它们提供的证书不是由您信任的CA 签名的。
例如:
给了我以下错误响应:
我添加了 -k:
并且没有错误消息。作为奖励,现在我安装了 apt-cyg。和 ca 证书。
The quickest way to get around the error is add on the -k option somewhere in your curl request. That option "allows connections to SSL cites without certs." (from curl --help)
Be aware that this may mean that you're not talking to the endpoint you think you are, as they are presenting a certificate not signed by a CA you trust.
For example:
gave me the following error response:
I added on -k:
and no error message. As a bonus, now I have apt-cyg installed. And ca-certificates.
来自
$ mancurl
:From
$ man curl
:@roens是正确的。这会影响所有 Anaconda 用户,并出现以下错误
curl:(77) 设置证书验证位置时出错:
CA文件:/etc/pki/tls/certs/ca-bundle.crt
CApath:无
解决方法是使用默认的系统curl 并避免弄乱前置的Anaconda
PATH
变量。您可以重命名 Anaconda curl 二进制文件:)
mv /path/to/anaconda/bin/curl /path/to/anaconda/bin/curl_anaconda
或 删除 Anaconda curl
conda 删除curl
$whichcurl
/usr/bin/curl
[0] Anaconda Ubuntu Curl Github 问题 https://github.com/conda/conda-recipes/issues/352
@roens is correct. This affects all Anaconda users, with below error
curl: (77) error setting certificate verify locations:
CAfile: /etc/pki/tls/certs/ca-bundle.crt
CApath: none
The workaround is to use the default system curl and avoid messing with the prepended Anaconda
PATH
variable. You can eitherRename the Anaconda curl binary :)
mv /path/to/anaconda/bin/curl /path/to/anaconda/bin/curl_anaconda
OR remove Anaconda curl
conda remove curl
$ which curl
/usr/bin/curl
[0] Anaconda Ubuntu curl Github issue https://github.com/conda/conda-recipes/issues/352
如果有人仍然遇到问题,请尝试这个,它对我有用。
删除
/etc/ssl/certs/
目录中的文件然后重新安装 ca-certificates:
当我尝试安装 Linuxbrew 时就是这样做的。
If anyone is still having trouble, try this, it worked for me.
Delete the files in your
/etc/ssl/certs/
directorythen reinstall ca-certificates:
Did this when I tried installing Linuxbrew.
我遇到了完全相同的问题。事实证明,我的
/etc/ssl/certs/ca-certificates.crt
文件格式错误。最后一个条目显示如下:在
-----END CERTIFICATE-----
之前添加换行符后,curl 能够处理证书文件。发现这一点非常烦人,因为我的 update-ca-certificates 命令没有给我任何警告。
这可能是也可能不是卷曲的版本特定问题,所以这是我的版本,只是为了完整性:
I had the exact same problem. As it turns out, my
/etc/ssl/certs/ca-certificates.crt
file was malformed. The last entry showed something like this:After adding a newline before
-----END CERTIFICATE-----
, curl was able handle the certificates file.This was very annoying to find out since my
update-ca-certificates
command did not give me any warning.This may or may not be a version specific problem of curl, so here is my version, just for completeness:
解决此问题的另一种方法是禁用证书验证:
Another alternative to fix this problem is to disable the certificate validation:
对于在 Windows 上的 XAMPP 上运行的 PHP 代码,我发现需要编辑 php.ini 以包含以下内容
,然后复制到文件 https://curl.haxx.se/ca/cacert.pem 并重命名为curl-ca-bundle.crt并将其放在\xampp路径下(我无法将curl.capath获取到工作)。我还发现 cURL 站点上的 CAbundle 不足以支持我要连接的远程站点,因此使用了 http://winampplugins.co.uk/curl/
For PHP code running on XAMPP on Windows I found I needed to edit php.ini to include the below
and then copy to a file https://curl.haxx.se/ca/cacert.pem and rename to curl-ca-bundle.crt and place it under \xampp path (I couldn't get curl.capath to work). I also found the CAbundle on the cURL site wasn't enough for the remote site I was connecting to, so used one that is listed with a pre-compiled Windows version of curl 7.47.1 at http://winampplugins.co.uk/curl/
这对我有用
,然后进入证书文件夹,然后
将 ca-certificates.crt 文件复制到
/etc/pki/tls/certs
如果没有 tls/certs 文件夹:创建一个并使用 chmod 777 -R 文件夹名称更改权限
This worked for me
then go into the certificates folder at
then you copy the ca-certificates.crt file into the
/etc/pki/tls/certs
if there is no tls/certs folder: create one and change permissions using chmod 777 -R folderNAME
默认情况下,curl 使用“捆绑包”执行
SSL
证书验证证书颁发机构 (CA)
公钥(CA 证书)。默认捆绑包名为curl-ca-bundle.crt;您可以指定一个备用文件
使用 --cacert 选项。
如果此
HTTPS
服务器使用由中表示的 CA 签名的证书捆绑包中,证书验证可能由于以下原因失败
证书有问题(可能已过期,或者名称可能已过期)
与 URL 中的域名不匹配)。
如果您想关闭curl对证书的验证,请使用
-k(或
--insecure
)选项。例如
curl performs
SSL
certificate verification by default, using a "bundle"of
Certificate Authority (CA)
public keys (CA certs). The defaultbundle is named curl-ca-bundle.crt; you can specify an alternate file
using the --cacert option.
If this
HTTPS
server uses a certificate signed by a CA represented inthe bundle, the certificate verification probably failed due to a
problem with the certificate (it might be expired, or the name might
not match the domain name in the URL).
If you'd like to turn off curl's verification of the certificate, use
the -k (or
--insecure
) option.for example
您的curl 似乎指向一个不存在的带有CA 证书或类似文件的文件。
有关使用curl 进行CA 证书的主要参考,请参阅:https://curl.se/docs/sslcerts。 html
It seems your curl points to a non-existing file with CA certs or similar.
For the primary reference on CA certs with curl, see: https://curl.se/docs/sslcerts.html
只需创建系统中缺少的文件夹即可。
并使用以下命令创建文件,
,然后将证书复制并粘贴到目标文件夹,该文件夹显示在您的错误中。我的是“
with message 'errorsettingcertificatelocations: CAfile: /etc/pki/ tls/certs/ca-bundle.crt CApath: none' in
" 确保将文件粘贴到错误中提到的确切位置。使用以下命令复制粘贴..已修复。
Just create the folders, which is missing in your system..
and create the file using the following command,
and then copy and paste the certificate to the destination folder, which is showing in your error.. mine was "
with message 'error setting certificate verify locations: CAfile: /etc/pki/tls/certs/ca-bundle.crt CApath: none' in
" make sure you paste the file to the exact location mentioned in the error. Use the following command to copy paste..Fixed.
对于 Windows:-
从 https://curl.se/docs/caextract.html 下载证书
将 cacert.pem 重命名为curl-ca-bundle.crt
将文件添加到以下任意位置
查看此内容了解详细信息 https:// /curl.se/docs/sslcerts.html
For windows :-
Download the certificate from https://curl.se/docs/caextract.html
Rename cacert.pem to curl-ca-bundle.crt
Add the file to any of the below locations
Check this for details https://curl.se/docs/sslcerts.html
我在尝试访问 Ubuntu 20.04 本地主机上的 docker 容器中运行的 elasticsearch 时遇到了这个curl 77问题。启动容器后:
检查不带 ssl 的curl:
curl --cacert http_ca.crt -u elastic https://localhost:9200 -k
小写-k
for不安全的连接。检查curl配置:
curl-config --configure
,注意到什么是ca-bundle:--with-ca-bundle=/etc/ssl/certs/ca-certificates。 crt
.将http_ca.crt文件从容器复制到:
/usr/local/share/ca-certificates/
,原始命令是此处。对 ca 证书运行更新:
sudo update-ca-certificates
。运行curl:
curl -u elastic:<密码>; https://localhost:9201
。最终得到了
“tagline”的回复:“你知道,用于搜索”
。更改<密码>到运行 Docker Image 时生成的那个。
另请注意,在我的机器上,elastic 是在端口 9201 上启动的(不知道为什么: sudo ss -tlpn | grep 9200 没有给我任何结果),我找到了该端口:
sudo netstat -ntlp
和程序名称是 docker-proxy。I came across this curl 77 problem while was trying to access elasticsearch running in docker container on Ubuntu 20.04 localhost. Afrer container was started:
Check curl without ssl:
curl --cacert http_ca.crt -u elastic https://localhost:9200 -k
lowercase-k
for insecure connection.Check curl configs:
curl-config --configure
, noticed what is ca-bundle:--with-ca-bundle=/etc/ssl/certs/ca-certificates.crt
.Copy http_ca.crt file from container to:
/usr/local/share/ca-certificates/
, original command is here.Run update on ca-certificates:
sudo update-ca-certificates
.Run curl:
curl -u elastic:<password> https://localhost:9201
.Finally got response with
"tagline" : "You Know, for Search"
.Change <password> to the one that was generated when Docker Image was run.
Also notice that on my machine elastic was started on port 9201 (don't know why: sudo ss -tlpn | grep 9200 gives me nothing), I have found the port with:
sudo netstat -ntlp
and Programm name was docker-proxy.我遇到了同样的问题:我正在构建一个基于 alpine 的 docker 映像,当我想卷曲到我的组织的网站时,会出现此错误。为了解决这个问题,我必须获得我公司的 CA 证书,然后,我必须将其添加到我的映像的 CA 证书中。
使用 OpenSSL 获取与网站相关的证书:
这将输出类似以下
内容:获取最后一个证书(
-----BEGIN CERTIFICATE-----
和-----END CERTIFICATE-----
标记)并将其保存到文件中(例如 mycompanyRootCA.crt)然后,当您从 alpine 构建 docker 镜像时,执行以下操作:
您的图像现在可以正常工作了!
I've got the same problem : I'm building an alpine based docker image, and when I want to curl to a website of my organisation, this error appears. To solve it, I have to get the CA cert of my company, then, I have to add it to the CA certs of my image.
Use OpenSSL to get the certificates related to the website :
This will output something like :
Get the last certificate (the content between the
-----BEGIN CERTIFICATE-----
and the-----END CERTIFICATE-----
markups included) and save it into a file (mycompanyRootCA.crt for example)Then, when you'll build your docker image from alpine, do the following :
Your image will now work properly!
我曾经在运行 composer update 时遇到此错误
我尝试了所有重新安装证书文件的命令,但问题没有解决。
我意识到错误是由于权限造成的
所以用这个命令解决了问题
I used to get this error when run composer update
And I tried all the commands to reinstall the cert file, but the problem was not solved.
I realized that the error is due to permission
So the problem was solved with this command
就其价值而言,检查正在运行哪个curl 也很重要。
我维护的共享计算机上的一个用户遇到了此错误。但事实证明,原因是他们安装了 Anaconda (http://continuum.io)。这样做将 Anaconda 的二进制路径放在标准
$PATH
之前,并且它带有自己的curl
二进制文件,它很难找到默认的证书。 > 安装在这台 Ubuntu 机器上。For what it's worth, checking
which curl
is being run is significant too.A user on a shared machine I maintain had been getting this error. But the cause turned out to be because they'd installed Anaconda (http://continuum.io). Doing so put Anaconda's binary path before the standard
$PATH
, and it comes with its owncurl
binary, which had trouble finding the default certs that were installed on this Ubuntu machine.只是发现这个解决方案非常适合我。
我从 这里
Just find this solution works perfectly for me.
I found this solution from here
在 git bash 中运行以下命令对我来说效果很好
Run following command in git bash that works fine for me
我使用 MobaXterm,实习生使用 Cygwin,所以即使使用 apt-cyg install ca-certificates 安装 ca-certificates 之后问题也没有解决。
我仍然收到以下错误:
curl: (77) error settingcertificate verifylocations: CAfile: /etc/ssl/certs/ca-certificates.crt CApath: none
然后我尝试列出文件 < code>/etc/ssl/certs/ca-certificates.crt 我找不到它。不过,我可以找到包含所有标准 CA 证书的
/usr/ssl/certs/ca-bundle.crt
,因此我复制了文件/usr/ssl/certs/ca-bundle.crt
code> as/etc/ssl/certs/ca-certificates.crt
问题得到解决。I use MobaXterm which intern uses Cygwin so even after installing
ca-certificates
usingapt-cyg install ca-certificates
problem didn't resolve.I was still getting the following error:
curl: (77) error setting certificate verify locations: CAfile: /etc/ssl/certs/ca-certificates.crt CApath: none
Then I tried listing the file
/etc/ssl/certs/ca-certificates.crt
and I couldn't find it. However I could find/usr/ssl/certs/ca-bundle.crt
with all standard CA certificates so I copied the file/usr/ssl/certs/ca-bundle.crt
as/etc/ssl/certs/ca-certificates.crt
and problem got resolved.