Deployment with Capistrano and Git: Solved
June 23rd, 2008
Finally! I may be the happiest blogrammer (that’s blogger + programmer = blogrammer) right now! I finally solved the multitude of problems described in a previous post. My requirements were pretty straightforward: I wanted to use a non-standard SSH port, and I wanted to rely on public key authentication, no passwords.
Capistrano kept spitting out the “Permission denied (publickey)” error. This made no sense to me, because I can SSH to my server just fine. I was totally stumped, until I found this. The problem was that I’m hosting my git repository and my application on the same server. Basically, my server was trying to ssh to itself, and it was getting denied, because I had not set up a public key for my server, only my local workstation.
At that point, the solution is simple. Just run the following command from your server: ssh-keygen -t rsa. Hit ‘enter’ through all the prompts (unless you want a password), and you now have a ssh public key at ~/.ssh/id_rsa.pub. Open this file in your favorite text editor, copy the entire file, and paste it at the bottom of ~/.ssh/authorized_keys. (There will likely only be one really long line in this file, so make sure you start a new line and then paste it in.)
set :application, "example.com"
set :scm, "git"
set :deploy_via, :remote_cache
set :repository, "ssh://username@example.com:11155/home/username/git_repos/repo.git"
default_run_options[:pty] = true
set :app_server, "example.com"
set :user, "username"
set :runner, user
set :port, 11155
set :deploy_to, "/home/username/public_html/#{app_server}"
role :app, application
role :web, application
role :db, application, :primary => true
Sorry, comments are closed for this article.