ArgumentError: Could not parse PKey: no start line

After updating my net-ssh gem to 2.6.x I started getting this error message from Capistrano:

ArgumentError: Could not parse PKey: no start line

The private key in question was completely fine though, given that it had been working in several other applications, including openssh itself, for quite some time. There seem to be some weird issues with net-ssh 2.6.x and Capistrano at the moment, and so I simply downgraded to v2.5.2 and everything worked fine once again:

gem uninstall net-ssh
gem install net-ssh -v 2.5.2

Keep deploying :)

Whenever Gem and Capistrano – Specifying the cronjob user

If you are using Capistrano in a project that relies on the Whenever gem to manage your crontab, it will update the crontab of the user that you use for your Capistrano deploys. So if, for example, you’d deploy with the user capistrano and your app runs under the user www-data, you could run into all sorts of trouble, e.g. permissions in case your cronjob creates new files.

Specifying the user under whom the cronjob command should be executed is relatively easy though. This mailing list entry tells us that we should add --user your_user as a parameter to the whenever command. The problem with that is that you don’t execute the command yourself, but the whenever gem’s Capistrano recipe does. So all we need to do is change the whenever_update_flags variable to meet our wishes. First the original line, and after that our modification:

# Old
_cset(:whenever_update_flags) { "–update-crontab #{fetch :whenever_identifier} –set #{fetch :whenever_variables}" }

# New
_cset(:whenever_update_flags) { "–update-crontab #{fetch :whenever_identifier} –set #{fetch :whenever_variables} –user www-data" }

You probably don’t want to change the whenever gem directly, so placing that line anywhere in the deploy.rb file should work just fine.

Capistrano ignoring SSH Agent Keys

Today I got pretty annoyed by Capistrano asking me for the password for my private key all the time when executing remote actions. This problem is caused by a buggy version of net Net-SSH Gem (namely v2.1.4, this is the related bug report). You can fix the problem by uninstalling the Gem and installing v2.0.24, which does not have the bug:

$ gem uinstall net-ssh
$ gem install net-ssh -v 2.0.24