You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用SSH推送代码至AWS CodeCommit时遇远程仓库读取错误求助

解决AWS CodeCommit推送时"Could not read from remote repository"错误

Hey there! Let's work through this error step by step—first, I caught a simple typo in your command, and then we'll check your SSH config and other common pitfalls.

1. 修正远程仓库添加命令

你写的命令是git add remote codecommit ssh://git-codecommit.us-east-1.amazonaws.com/Test-codecommit-repo,这里有两个关键问题:

  • 命令语法错误:正确的添加远程仓库命令应该是git remote add(顺序搞反了)
  • URL路径缺失:CodeCommit的SSH URL必须包含/v1/repos/前缀,否则无法正确定位到仓库

正确的命令应该是:

git remote add codecommit ssh://git-codecommit.us-east-1.amazonaws.com/v1/repos/Test-codecommit-repo

2. 检查SSH配置文件的完整性

你的~/.ssh/config开头是对的,但要确保配置完整且格式正确,完整的配置应该像这样(替换成你的私钥文件路径):

Host git-codecommit.*.amazonaws.com
  User AP***************UQ
  IdentityFile ~/.ssh/your-private-key-file.pem

还要注意两个细节:

  • IdentityFile必须指向你上传到IAM用户的公钥对应的私钥文件
  • 配置文件和私钥的权限必须符合SSH安全要求:执行chmod 600 ~/.ssh/config和chmod 400 ~/.ssh/your-private-key-file.pem,SSH对文件权限要求很严格,权限过宽会直接拒绝连接

3. 测试SSH连接是否正常

运行以下命令验证SSH是否能正常连接到CodeCommit:

ssh git-codecommit.us-east-1.amazonaws.com

如果配置正确,你会看到类似这样的提示:

You have successfully authenticated over SSH. You can use Git to interact with AWS CodeCommit. Interactive shells are not supported.

如果这里报错,说明问题出在SSH配置或IAM权限,而不是git推送命令本身。

4. 确认IAM用户的权限

确保你的IAM用户(和SSH密钥关联的那个)拥有CodeCommit的必要权限,比如:

  • codecommit:GitPull
  • codecommit:GitPush

可以先给用户附加AWSCodeCommitPowerUser这个托管策略做测试,之后再根据需要调整为自定义权限。

5. 验证仓库名称和区域是否匹配

最后再确认两点:

  • 仓库名称Test-codecommit-repo和AWS控制台里的完全一致(CodeCommit对大小写敏感)
  • URL里的区域us-east-1是仓库创建时选择的区域

把这些都检查修正后,再运行git push codecommit develop应该就能成功推送了。

内容的提问来源于stack exchange,提问作者Vidhan Dosi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 03:31:40