Capistrano keeps asking for password

When deploying with Capistrano, you probably want to do it with a minimum of kicking and screaming. One of the obstacles that lies in your way is the constant requests for passwords which pop up if you haven’t set everything up properly.
* executing `invoke'
  * executing "echo $LOGNAME"
    servers: [""]
Enter passphrase for /home/paul/.ssh/id_rsa:

How do you avoid this? It turns out there are a couple of common problems that cause Cap to keep asking you for your password.

Accessing source control with SSH

Cap has to pull your data out of source control, and it may need to ssh somewhere to get it (check your :repository setting). Even if you’re using the same username to access source control (and you probably are), it still has to ssh from your remote machine to the repo – even though it might be located on the same remote machine. The solution for this is pretty simple: you need to tell Capistrano to use ssh user forwarding.

set :ssh_options, {:forward_agent => true}

You can read about agent forwarding here if you’re not familiar with it.

Missing public key

Even if you have password-less access to the remote machine in question using a private key, you may still be asked for a password because Capistrano requires you to have the public key which matches that private key. (Thanks to thebaldwin for pointing this out) If your ~/.ssh folder only contains the id_rsa, you need to either put the in there too, or recreate it like this:

ssh-keygen -y -f ~/.ssh/id_rsa > ~/.ssh/