我有一个Rails 5和Capistrano 3应用程序。
我能够将代码推送到git存储库并将其从那里拉出来。
但是,当我尝试通过Capistrano将代码部署到(DigitalOcean)服务器时,我收到以下错误消息:
00:02 git:check
01 git ls-remote git@bitbucket.org:username/reponame.git HEAD
01 repository access denied.
01 fatal: Could not read from remote repository.
01
01 Please make sure you have the correct access rights
01 and the repository exists.
(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as deployer@IP: git exit status: 128
git stdout: Nothing written
git stderr: repository access denied.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
SSHKit::Command::Failed: git exit status: 128
git stdout: Nothing written
git stderr: repository access denied.
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 as deployer@IP: git exit status: 128
git stdout: Nothing written
git stderr: repository access denied.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
** DEPLOY FAILED
我做了什么:我在我的mac上生成了一个新的SSH密钥,输出位于名为project_name
和project_name.pub
的文件中。然后我运行了这个命令:
cat ~/.ssh/project_name.pub | pbcopy
并将此密钥代码粘贴到Bitbucket存储库的设置部分" SSH密钥"。
在Capistrano配置文件中,我有以下内容:
set :ssh_options, {
keys: %w(/Users/my_name/.ssh/project_name),
forward_agent: true,
auth_methods: %w(publickey password),
port: 22
}
当我运行cap production deploy
时,系统会要求我输入密码,之后由于上述错误(Please make sure you have the correct access rights and the repository exists.
),部署过程失败。
如何设置密钥/修复部署问题?
答案 0 :(得分:1)
看起来你的SSH密钥没有被转发。通常这是因为您的SSH密钥不可用于ssh-agent
进行转发。 Github有a good writeup on this,但您可能只需要运行:ssh-add project_name
。
您可能还需要更改Github文章所涉及的SSH配置,但我只是从ssh-add
开始。
请注意,我基于您的forward agent: true
的假设是您尝试通过将本地SSH密钥转发到Github来进行部署,而不是使用应用服务器上存在的部署密钥。如果情况并非如此,并且您的部署密钥位于服务器上,则只需将其设置为false。
答案 1 :(得分:0)
希望您在存储库中正确添加了ssh密钥。我认为您正在使用git clone https://user@bitbucket.org/appname.git
这样的HTTPS克隆存储库,因为bitbucket是私有存储库,请使用git clone https://user@bitbucket.org/appname.git
这样的ssh替换https,请不要记住在小滴中创建ssh密钥时添加密码,请将其留空。希望此帮助对将来的rails爱好者有帮助。