We have a EC2 instance, and our capistrano setup requires ssh. To connect through ssh normally, I use a .pem file for connecting to the server. how do I utilize this .pem file when using capistrano to deploy?
Asked
Active
Viewed 1.3k times
2 Answers
39
for capistrano 3 the syntax is somewhat different
set :pty, true
set :ssh_options, {
forward_agent: true,
auth_methods: ["publickey"],
keys: ["/path/to/key.pem"]
}

Kinjal Dixit
- 7,777
- 2
- 59
- 68
37
In deploy.rb
set these configuration values:
default_run_options[:pty] = true
ssh_options[:forward_agent] = true
ssh_options[:auth_methods] = ["publickey"]
ssh_options[:keys] = ["/path/to/key.pem"]
For Capistrano 3 use:
set :pty, true
set :ssh_options, {
forward_agent: true,
auth_methods: %w[publickey],
keys: %w[/path/to/key.pem]
}

NARKOZ
- 27,203
- 7
- 68
- 90
-
okay, I had all those but "publickey"... So now I'm getting this error: Permission denied (publickey). fatal: The remote end hung up unexpectedly *** [deploy:update_code] rolling back – Tyler Jones Oct 20 '12 at 06:14
-
do you have a public key at server? – NARKOZ Oct 20 '12 at 12:40
-
is there a way to have capistrano be verbose in its output? – Tyler Jones Oct 25 '12 at 20:37
-
7You have to use: ssh_options[:auth_methods] = ["publickey"] to avoid NoMethodError: undefined method `each' for "publickey":String error – Alexey Kucherenko Jan 16 '13 at 02:33
-
You won't get a file-not-found error if the keyfile is not found, so double check the path to the key. – Hugo Logmans Sep 14 '15 at 09:51
-
in Capistrano 3.10 I get ```NameError: undefined local variable or method `default_run_options' for main:Object```; see other answer for Capistrano 3 syntax – Jason FB Mar 15 '18 at 13:33
-
TylerJones `:ssh_options, { verbose: :debug }` will give you verbose output – SMAG May 30 '20 at 08:57