“Could not read from remote repository”根源在SSH配置未通,需先用ssh -T和git ls-remote验证密钥与host配置,再确保composer.json中URL与~/.ssh/config的Host逐字一致,清缓存并加-vvv确认实际命令。

“Could not read from remote repository”不是 Composer 的 bug,而是 Git 拉取失败后抛出的原始错误——根源几乎总在 SSH 配置没走通,而不是 composer.json 写错了。
ssh -T 测试不成功,其他全白搭
Composer 调用的是系统 git,git 走的是你 ~/.ssh/config 里的规则,但前提是 ssh 命令本身能连通。很多同学跳过这步直接改 composer.json,结果反复重试都没用。
- 运行
ssh -T git@github.com(或你仓库对应域名,如git@gitlab.example.com)必须返回类似Hi xxx! You've successfully authenticated... - 如果报
Permission denied (publickey):检查私钥文件权限是否为600(chmod 600 ~/.ssh/id_rsa*),且~/.ssh/config中对应 Host 的IdentityFile路径写对了 - 如果报
The authenticity of host 'xxx' can't be established:这是首次连接,需手动接受 host key(或内网环境可临时加-o StrictHostKeyChecking=no) - 若用别名(如
github-work),测试必须用别名:ssh -T git@github-work,不能只测github.com
composer.json 里 URL 必须匹配 SSH 配置的 Host 名
Git 只有在 URL 的主机部分和 ~/.ssh/config 里的 Host 行**逐字一致**时,才会加载对应密钥。写成 git@github.com:user/repo.git 就永远走不到你配的 Host github-personal。
围绕关键发现、作用机制、临床相关性及研究局限性展开讨论。适用于撰写或优化任何生物医学论文的“讨论(Discussion)”部分——包括结果解读、与既往文献关联、阐释意外发现、界定研究局限性,以及撰写结论。当用户输入以下任一指令时也会自动触发该功能: - “write my discussion” - “help me discuss my findings” - “how do I compare to prior studies” - “write the limitations par
- 把
git@github.com:user/repo.git改成git@github-personal:user/repo.git(假设你在 config 里写了Host github-personal) - 确保
~/.ssh/config中该 Host 区块包含完整字段:HostName github.com、User git、IdentityFile ~/.ssh/id_rsa_personal、IdentitiesOnly yes - URL 中不能出现
https://或git://;也不能用斜杠代替冒号:git@host/group/repo.git是错的,必须是git@host:group/repo.git
Git 缓存和 Composer 缓存会掩盖真实问题
一次失败后,Composer 可能降级尝试 HTTPS,后续再跑 composer install 看似成功,其实绕过了 SSH——你根本没修好密钥问题,只是暂时躲过去了。
- 清掉 Git 的 credential helper 缓存:
git config --global --unset credential.helper(如果启用了) - 删掉 Composer 的 VCS 缓存:
rm -rf ~/.composer/cache/vcs/(全局)或项目下vendor/composer/installed.json - 加
-vvv参数看真实命令:composer install -vvv 2>&1 | grep 'git clone',确认日志里执行的 URL 和协议是你预期的
内网私有 Git 服务器要额外注意 host 解析和端口映射
内网地址不像 github.com 那样天然可解析,SSH 配置稍有偏差就会 fallback 到 HTTPS 或直接失败。
- URL 中的主机名(如
git@10.0.1.5)必须和~/.ssh/config里的Host完全一致——不能写成git@git.internal除非你真配了 DNS 或/etc/hosts - 非标端口(如 2222)不能写在 URL 里,得靠
Port 2222显式写在 config 对应 Host 区块中 - 务必验证
git ls-remote git@your-host:group/repo.git能返回 refs 列表;这个比ssh -T更贴近 Composer 实际行为
最容易被忽略的是:SSH 配置生效 ≠ Git clone 成功。中间差了一个 git ls-remote 的验证环节——它会触发完整的密钥加载、host key 校验、权限检查,而 ssh -T 只校验到用户认证层。不跑这一步,你永远不知道 Composer 真正卡在哪。

















