90% Conan私有仓库认证失败是因remote配置不合法、凭据未加载或URL与认证域不严格匹配;需验证remote URL带协议且无尾斜杠、registry.json路径及格式正确、域名端口精确匹配。

conan 私有仓库认证失败,90% 的情况不是密码错了,而是凭证压根没送出去——conan 静默跳过认证、不报错、不发请求,最后只甩一句 ERROR: Unable to find 'xxx/1.0.0@user/channel' in remotes 或 401 Unauthorized。核心问题就三个:远程源配置是否合法、凭据是否加载、URL 与认证域是否严格匹配。
conan remote add 的 URL 必须带协议且末尾无斜杠
很多团队把私有 Artifactory/Nexus 地址写成 https://artifactory.internal.com/conan(少斜杠)或 artifactory.internal.com/conan(缺协议),conan 会解析失败但不提示,后续所有操作都绕过该 remote。
- 正确写法:
conan remote add myrepo https://artifactory.internal.com/artifactory/api/conan/conan-local(Artifactory 路径必须含/api/conan/xxx) - Nexus 3 示例:
conan remote add myrepo https://nexus.internal.com/repository/conan-group(末尾不能加/) - 运行
conan remote list检查输出中 URL 是否完整可访问;再用curl -I https://artifactory.internal.com/artifactory/api/conan/conan-local/v1/ping确认返回 HTTP 200
auth.json 必须放在正确路径且格式合法
conan 不读 ~/.docker/config.json,也不读全局 auth.json —— 它只认自己定义的凭据文件,且路径、权限、字段名全都有硬性要求。
- Linux/macOS:文件必须是
~/.conan/registry.json(Conan 2.x)或~/.conan/.conan_login_credentials(Conan 1.x),不是auth.json - Conan 2.x 推荐用命令登录:
conan remote login myrepo -p,它会自动写入-u registry.json - 手动编辑
registry.json时,remotes下的name字段必须和conan remote list中显示的 remote 名完全一致(大小写敏感) - 如果用 token(如 Artifactory API Key),
-u填admin或对应用户,-p填 token 字符串,不要加Bearer前缀
CI 环境下凭据无法继承,必须显式注入
GitLab CI、GitHub Actions 或 Jenkins 执行 conan install 时,默认没有登录态。你本地 conan remote login 过,对 CI 完全无效。
- 推荐方式:用环境变量
CONAN_LOGIN_USERNAME_myrepo和CONAN_PASSWORD_myrepo(myrepo替换为你的 remote 名) - 不要在脚本里写
echo $TOKEN | conan remote login...——conan会把 stdin 当交互输入,导致卡住 - Docker 构建中,避免挂载
~/.conan目录:不同用户 UID 可能导致权限拒绝;改用conan config set storage.path=/tmp/conan_cache隔离缓存 - 验证是否生效:在 CI 脚本中加一行
conan remote list-ref,输出应包含已登录的 remote 名
HTTPS 仓库证书不受信时,conan 不会自动降级
内网自签名证书场景下,conan 默认拒绝连接,错误类似 SSL certificate problem: unable to get local issuer certificate,它不会像 curl -k 那样忽略校验。
- 解决方法:将 CA 证书(PEM 格式)路径加入 Conan 配置:
conan config set general.ssl_verify=True(确保开启),再执行conan config set general.ca_path=/path/to/internal-ca.crt - 证书文件必须是纯 PEM,以
-----BEGIN CERTIFICATE-----开头,不能是 DER 或 PFX - 若用
conan-center代理私有源,注意conan-center本身是 HTTPS,但你的私有 remote 是 HTTP —— 此时需额外设conan config set general.verify_ssl=False,仅对那个 remote 生效(不推荐,应优先配证书)
真正容易被忽略的是:Conan 2.x 的 registry.json 里,每个 remote 的凭据是按域名+端口精确匹配的。比如 remote URL 是 https://artifactory.internal:8443/...,那么凭据 key 就必须是 "artifactory.internal:8443",写成 "artifactory.internal" 或 "https://artifactory.internal:8443" 都会失效——它不解析 URL,只做字符串比对。











