Rails: Capistrano. Permisssion Denied (public key)
I was looking for a way to deploy my application using capistrano. I am currently hosting a small private repo on github and a local server to try deploying my test. I ran into the problem and the error message below.
I did the following
-
Generate ssh key on server and add successfully to deploy keys to repo and checked out (git @ github.com)
-
Create ssh key on client and add it to deploy keys to repo
-
set up a private repository. And have a deployer account with deployment rights
- configured deploy.rb and production rb to track many other templates.
I still can't figure out why it is giving me an error like this
DEBUG [a5554d3d] Command: /usr/bin/env chmod +x /tmp/App/git-ssh.sh
INFO [a5554d3d] Finished in 0.020 seconds with exit status 0 (successful).
INFO [b1517df1] Running /usr/bin/env git ls-remote --heads git@github.com:aceofw
ings/App.git as deploy@192.168.1.84
DEBUG [b1517df1] Command: ( GIT_ASKPASS=/bin/echo GIT_SSH=/tmp/App/git-ssh
.sh /usr/bin/env git ls-remote --heads git@github.com:aceofwings/App.git )
DEBUG [b1517df1] Permission denied (publickey).
DEBUG [b1517df1] fatal: Could not read from remote repository.
DEBUG [b1517df1]
DEBUG [b1517df1] Please make sure you have the correct access rights
DEBUG [b1517df1] and the repository exists.
(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as deploy@192.168.1.84:
git exit status: 128
git stdout: Nothing written
git stderr: Permission denied (publickey).
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
Deploy.rb file
###############Deploy.rb##################
# config valid only for current version of Capistrano
lock '3.4.0'
set :repo_url, 'git@github.com:aceofwings/App.git'
set :application, 'App'
set :user, 'deploy'
#set :pty, true
# Default branch is :master
# ask :branch, `git rev-parse --abbrev-ref HEAD`.chomp
# Default value for linked_dirs is []
# set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', 'public/system')
namespace :deploy do
after :restart, :clear_cache do
on roles(:web), in: :groups, limit: 3, wait: 10 do
# Here we can do anything such as:
# within release_path do
# execute :rake, 'cache:clear'
# end
end
end
end
Production.rb
server '192.168.1.84', user: 'deploy', roles: %w{app db web}
#set :stage, :production
role :app, %w{deploy@192.168.1.84}
role :web, %w{deploy@192.168.1.84}
role :db, %w{deploy@192.168.1.84}
set :ssh_options, {
forward_agent: false,
auth_methods: %w(password),
password: 'Deploy4Real',
user: 'deploy'
}
source to share
I had a similar problem. It turns out the SSH agent was not working. I found this by looking at the Capistrano documentation: http://capistranorb.com/documentation/getting-started/authentication-and-authorisation/
Running this command:
$ ssh-add -l
showed me that my public key was not added to the agent, so I had to add it:
$ ssh-add
Added identity: /Users/me/.ssh/id_rsa (/Users/me/.ssh/id_rsa)
After that my Capistrano deployment worked.
source to share
You must install in production.rb:
forward_agent: true
I had the same problem with Capistrano 3.4. As of Capistrano 3.2.1, it seemed to ignore this setting.
You can use capistrano-ssh-doctor to troubleshoot possible configuration issues.
source to share
I think your capistrano may have old files in the git cache, perhaps from renaming a repository or something. Try to delete the folder cached-copy
in the folder shared
on the server, so capistrano will pull your repo again.
source to share