Windows 上安装 devsidecar 后,使用 WSL ubuntu ssl 报错

文章目录

  • [1. 问题原因](#1. 问题原因)
  • [2. 解决方案](#2. 解决方案)
    • [方法 1:禁用 SSL 验证(不推荐,仅临时测试)](#方法 1:禁用 SSL 验证(不推荐,仅临时测试))
    • [方法 2:将 Windows 证书同步到 WSL](#方法 2:将 Windows 证书同步到 WSL)
    • [方法 3:手动配置环境变量](#方法 3:手动配置环境变量)
    • [方法 4:完全绕过代理(推荐终极方案)](#方法 4:完全绕过代理(推荐终极方案))
  • 预防措施
  • 总结

在 Windows 上使用 DevSidecar(开发者边车工具)后,WSL Ubuntu 中遇到 SSL 证书错误(如 SSL certificate problem: unable to get local issuer certificate),通常是因为代理工具修改了系统证书,但 WSL 未正确同步这些更改。以下是解决方案:

1. 问题原因

DevSidecar 或类似代理工具会安装自签名根证书到 Windows 的证书存储(如 Charles Proxy 或 Fiddler 的证书)。

WSL Ubuntu 默认使用自己的证书存储(/etc/ssl/certs),无法自动识别 Windows 中添加的证书,导致 SSL 验证失败。

2. 解决方案

方法 1:禁用 SSL 验证(不推荐,仅临时测试)

在命令中临时跳过 SSL 验证(如 curl、git、pip):

bash 复制代码
# 对于 curl
curl -k https://example.com

# 对于 git
git config --global http.sslVerify false

# 对于 pip
pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org package_name

⚠️ 这会降低安全性,仅用于临时测试。

方法 2:将 Windows 证书同步到 WSL

  1. 导出 DevSidecar 的根证书:

    • 在 Windows 中打开 certmgr.msc,找到 DevSidecar 的根证书(通常位于 受信任的根证书颁发机构)。

    • 右键导出为 .pem 或 .crt 格式(如 devsidecar.crt)。

  2. 将证书复制到 WSL:

bash 复制代码
# 从 Windows 复制到 WSL(假设证书在 C:\)
cp /mnt/c/devsidecar.crt /usr/local/share/ca-certificates/
  1. 更新 WSL 的证书存储:
bash 复制代码
sudo update-ca-certificates
  • 输出应显示 1 added, 0 removed。
  1. 验证证书是否生效:
bash 复制代码
curl https://example.com  # 应不再报 SSL 错误

方法 3:手动配置环境变量

如果代理工具提供了 CA 证书,可显式指定证书路径:

bash 复制代码
# 对于 curl
curl --cacert /path/to/devsidecar.crt https://example.com

# 对于 git
git config --global http.sslCAInfo /path/to/devsidecar.crt

# 对于 pip
pip install --cert /path/to/devsidecar.crt package_name

方法 4:完全绕过代理(推荐终极方案)

如果不需要在 WSL 中使用代理,直接关闭 DevSidecar 并清除代理设置:

  1. 重置 WSL 的代理配置:
bash 复制代码
unset http_proxy https_proxy all_proxy
  1. 检查 Git 代理:
bash 复制代码
git config --global --unset http.proxy
git config --global --unset https.proxy
  1. 常见错误及修复
  • 错误 1:curl: (60) SSL certificate problem: unable to get local issuer certificate

    修复:执行方法 2 同步证书。

  • 错误 2:pip is configured with locations that require TLS/SSL, but the ssl module in Python is not available

    修复:重新安装 Python 的 SSL 模块:

bash 复制代码
sudo apt-get install libssl-dev
sudo apt-get install python3-pip --reinstall
  • 错误 3:Certificate verification failed: The certificate is NOT trusted
    修复:确保证书路径正确且已更新:
bash 复制代码
sudo update-ca-certificates --fresh
export SSL_CERT_DIR=/etc/ssl/certs

预防措施

  1. 统一代理配置:

    • 在 WSL 中显式设置代理环境变量(与 Windows 代理一致):
    bash 复制代码
    export http_proxy=http://<Windows_IP>:<DevSidecar_PORT>
    export https_proxy=http://<Windows_IP>:<DevSidecar_PORT>

    替换 <Windows_IP> 为 Windows 主机的 IP(如 127.0.0.1),<DevSidecar_PORT> 为 DevSidecar 的端口(默认可能为 15732)。

  2. 使用 WSL 2 的自动 DNS 解析:

    • WSL 2 默认共享 Windows 的网络,但证书仍需手动同步。

总结

  • 优先方案:同步 Windows 证书到 WSL(方法 2)。
  • 临时方案:禁用 SSL 验证(方法 1)。
  • 终极方案:关闭代理并清除配置(方法 4)。

如果问题仍存在,请检查 DevSidecar 的日志或尝试重启 WSL:

bash 复制代码
wsl --shutdown
相关推荐
Molesidy8 小时前
【UAV】基于PX4+Ubuntu24.04.3的无人机制作的开发环境搭建
ubuntu·无人机·px4·gazebo·uav
绿箭柠檬茶11 小时前
Ubuntu 使用 Samba 共享文件夹
linux·运维·ubuntu
你是人间五月天11 小时前
sentinel实现控制台与nacos数据双向绑定
windows·sentinel
小猫挖掘机(绝版)14 小时前
通过tailscale实现一台电脑上vscode通过ssh连接另一台电脑上的VMware Linux 虚拟机
linux·windows·vscode·ubuntu·ssh
剑客的茶馆15 小时前
新服务器从0开始搭配Ubuntu+Conda+Docker+Dify
服务器·ubuntu·docker·conda·dify
你我约定有三20 小时前
java--泛型
java·开发语言·windows
self_myth20 小时前
[特殊字符] 深入理解操作系统核心特性:从并发到分布式,从单核到多核的全面解析
windows·macos·wpf·harmonyos
正在走向自律20 小时前
Ubuntu系统下Python连接国产KingbaseES数据库实现增删改查
开发语言·数据库·python·ubuntu·kingbasees·ksycopg2
weixin_4569042721 小时前
CentOS与Ubuntu的详细区别
linux·ubuntu·centos
zfxwasaboy21 小时前
linux Kbuild详解关于fixdep、Q、quiet、escsq
android·linux·ubuntu