Ruby on Rails部署报错:Could not read from remote repository求助
Github Actions部署到AWS失败:
Could not read from remote repository 问题描述
此前通过Github Actions将代码从Github部署到AWS一直正常,相同代码突然失效,抛出Could not read from remote repository错误。已确认Github Actions可连接远程服务器,但无法从Github拉取最新代码。
使用的Gem列表
- gem 'capistrano-rails'
- gem 'capistrano', '~> 3.2'
- gem 'capistrano-rails-console', require: false
- gem 'capistrano-rails'
- gem 'capistrano-yarn'
- gem 'capistrano-bundler'
- gem "sshkit", "1.18.2"
- gem 'rails', '5.1.6.2'
- gem 来自仓库:https://github.com/miloserdow/capistrano-deploy/tree/v2.2
Github Actions配置
name: Deployment on: workflow_dispatch: jobs: deploy_to_xyz: name: Deploy to xyz runs-on: ubuntu-20.04 env: CAP_BRANCH: zzz AWS_KEY_ID: xxxx AWS_SECRET_KEY: xxxx AWS_REGION: xxxx steps: - uses: actions/checkout@v2 - uses: ruby/setup-ruby@v1 with: ruby-version: 2.5.9 bundler-cache: true - uses: miloserdow/capistrano-deploy@v2.2 with: target: staging enc_rsa_key_pth: "xxxx" deploy_key: xxxx - name: Success # code related to failure - name: Fail deploy notification # code related to failure
错误日志
00:00 git:wrapper 01 mkdir -p /tmp ✔ 01 user@xxxxxIp.345s ✔ 01 user@xxxxxip 1.349s Uploading /tmp/git-ssh-xxxxx-runner.sh 100.0% Uploading /tmp/git-ssh-xxxxx-runner.sh 100.0% 02 chmod 700 /tmp/git-ssh-xxxxx-runner.sh ✔ 02 user@xxxxxxIP 0.342s ✔ 02 user@xxxxxxIP 0.342s 00:02 git:check 01 git ls-remote git@github.com:xxxx/xxxx.git HEAD 01 ERROR: Repository not found. 01 fatal: Could not read from remote repository. 01 01 Please make sure you have the correct access rights 01 and the repository exists. #<Thread:0x000055aecb8f72b0@/home/runner/work/xxxx/xxxx/vendor/bundle/ruby/2.5.0/gems/sshkit-1.18.2/lib/sshkit/runners/parallel.rb:10 run> terminated with exception (report_on_exception is true): /home/runner/work/xxxx/xxxx/vendor/bundle/ruby/2.5.0/gems/sshkit-1.18.2/lib/sshkit/runners/parallel.rb:15:in rescue in block (2 levels) in execute : Exception while executing on host ip: git exit status: 128 (SSHKit::Runner::ExecuteError) git stdout: Nothing written git stderr: ERROR: Repository not found. fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. from /home/runner/work/xxxx/xxxx/vendor/bundle/ruby/2.5.0/gems/sshkit-1.18.2/lib/sshkit/runners/parallel.rb:11:in block (2 levels) in execute 01 ERROR: Repository not found. 01 fatal: Could not read from remote repository. 01 01 Please make sure you have the correct access rights 01 and the repository exists. #<Thread:0x000055aecb8f7738@/home/runner/work/xxxx/xxxx/vendor/bundle/ruby/2.5.0/gems/sshkit-1.18.2/lib/sshkit/runners/parallel.rb:10 run> terminated with exception (report_on_exception is true): /home/runner/work/xxxx/xxxx/vendor/bundle/ruby/2.5.0/gems/sshkit-1.18.2/lib/sshkit/runners/parallel.rb:15:in rescue in block (2 levels) in execute : Exception while executing on host ip: git exit status: 128 (SSHKit::Runner::ExecuteError) git stdout: Nothing written git stderr: ERROR: Repository not found. fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. from /home/runner/work/xxxx/xxxx/vendor/bundle/ruby/2.5.0/gems/sshkit-1.18.2/lib/sshkit/runners/parallel.rb:11:in block (2 levels) in execute (Backtrace restricted to imported tasks) cap aborted! SSHKit::Runner::ExecuteError: Exception while executing on host ip: git exit status: 128 git stdout: Nothing written git stderr: ERROR: Repository not found. fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. Caused by: SSHKit::Command::Failed: git exit status: 128 git stdout: Nothing written git stderr: ERROR: Repository not found. fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. Tasks: TOP => deploy:check => git:check (See full trace by running task with --trace) The deploy has failed with an error: Exception while executing on host ip: git exit status: 128 git stdout: Nothing written git stderr: ERROR: Repository not found. fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. ** DEPLOY FAILED ** Refer to log/capistrano.log for details. Here are the last 20 lines: INFO [8a54f66e] Running /usr/bin/env git ls-remote git@github.com:xxxx/xxxx.git HEAD on ip DEBUG [40ed32b1] ERROR: Repository not found. DEBUG [40ed32b1] fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. DEBUG [5dd77983] ERROR: Repository not found. DEBUG [5dd77983] fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. Error: Error: The process /opt/hostedtoolcache/Ruby/2.5.9/x64/bin/bundle failed with exit code 1
可能的排查方向
- Deploy Key权限或有效性问题
- 检查
deploy_key对应的SSH密钥对是否过期、被撤销,或者公钥是否从Github仓库的Deploy Keys中被移除 - 确认该Deploy Key拥有仓库的读取权限(私有仓库必须配置)
- 检查
- 仓库地址或分支配置错误
- 检查Capistrano配置中的
repo_url是否正确,注意Github仓库地址大小写敏感,避免拼写错误 - 确认环境变量
CAP_BRANCH指定的分支zzz确实存在于目标仓库中
- 检查Capistrano配置中的
- SSH密钥传递问题
- 检查
miloserdow/capistrano-deploy插件的enc_rsa_key_pth和deploy_key参数是否配置正确,密钥内容需完整(包含正确的换行符,无多余空格) - 手动在远程服务器执行
git ls-remote git@github.com:xxxx/xxxx.git HEAD,验证是否使用正确的密钥认证
- 检查
- Github侧权限变更
- 检查仓库访问权限是否被修改(如从公开转为私有),或组织权限调整导致Deploy Key失效
- 确认AWS服务器的防火墙/安全组未拦截Github的IP地址(虽然能连接服务器,但拉取代码的出站请求可能被限制)
- 依赖缓存或版本冲突
- 尝试在Github Actions中禁用
bundler-cache: true,重新安装依赖后测试,排除旧版本缓存导致的兼容性问题 - 确认
sshkit1.18.2版本与其他Capistrano插件无冲突
- 尝试在Github Actions中禁用
内容的提问来源于stack exchange,提问作者kashif
相关产品推荐
相关产品推荐

