title: Capistrano bitbucket - Permission denied (publickey)
body: <p>I'm trying to deploy my application using Capistrano towards my DigitalOcean server.</p>
  
  <p>This isn't the first time I've configured a RoR server on DigitalOcean with Capistrano deploys that's why I'm confused; I haven't changed anything in my workflow.</p>
  
  <p>Here is my Capistrano configuration file:</p>
  
  <pre><code>require 'bundler/capistrano'
  require 'rvm/capistrano'
  
  set :application, "foobar"
  set :repository,  "git@bitbucket.org:sergiotapia/foobar.git"
  set :ping_url, "http://192.168.1.1/"
  set :scm, :git
  set :scm_verbose, true
  default_run_options[:pty] = true
  
  set :user, "sergiotapia" # The user on the VPS server.
  set :password, "hunter2"
  set :use_sudo, false
  set :deploy_to, "/home/sergiotapia/www/#{application}"
  set :deploy_via, :remote_cache
  set :keep_releases, 1
  set :rails_env, "production"
  set :migrate_target, :latest
  
  role :web, "192.168.1.1"
  role :app, "192.168.1.1"
  
  namespace :deploy do
    task :start do ; end
    task :stop do ; end
    task :restart, roles: :app, except: { no_release: true } do
      run "sudo touch #{File.join(current_path,'tmp','restart.txt')}"
    end
  end
  
  # Add this to add the `deploy:ping` task:
  namespace :deploy do
    task :ping do
      system "curl --silent #{fetch(:ping_url)}"
    end
  end
  
  namespace :gems do
    task :bundle, :roles =&gt; :app do
      run "cd #{release_path} &amp;&amp; bundle install --without development &amp;&amp; rake db:migrate RAILS_ENV=production"
    end
  end
  
  after "deploy:update_code", "gems:bundle"
  
  # Add this to automatically ping the server after a restart:
  after "deploy:restart", "deploy:ping"
  </code></pre>
  
  <p>When running a <code>cap deploy:setup</code> and <code>cap deploy:check</code> everything comes back green-lighted (working fine). </p>
  
  <p>It fails on the actual <code>cap deploy</code> command.</p>
  
  <pre><code>** [192.168.1.1 :: out] Enter passphrase for key '/home/sergiotapia/.ssh/id_rsa':
  Password: 
  ** [192.168.1.1 :: out]
  ** [192.168.1.1 :: out] Permission denied (publickey).
  ** [192.168.1.1 :: out]
  ** [192.168.1.1 :: out] fatal: Could not read from remote repository.
  ** [192.168.1.1 :: out]
  ** [192.168.1.1 :: out]
  ** [192.168.1.1 :: out] Please make sure you have the correct access rights
  ** [192.168.1.1 :: out]
  ** [192.168.1.1 :: out] and the repository exists.
  ** [192.168.1.1 :: out]
  </code></pre>
  
  <p>I've already added my <code>id_rsa.pub</code> file to BitBucket and also made sure it's added to my SSH agent using the <code>ssh-add -l</code> command. </p>
  
  <p>Even testing out SSH from the remote server works fine:</p>
  
  <pre><code>sergiotapia@tappia:~/www$ ssh -T git@bitbucket.org
  logged in as sergiotapia.
  
  You can use git or hg to connect to Bitbucket. Shell access is disabled.
  </code></pre>
  
  <p>So what gives, why is denying me access to the repository on BitBucket?</p>
  
  <p>Is Capistrano running as a user other than <code>sergiotapia</code>? Would that be the cause of it?</p>