diff --git a/README.md b/README.md index 83c077e..82775d1 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,12 @@ In your Capfile, require the gem: And in your deploy stage, after you register servers and services, create the one time keys: + server ENV['HOST'], user: ENV['USER'], roles: %w{app} Capistrano::OneTimeKey.generate_one_time_key! + # Optional modification of ssh options. + ssh_opts = fetch(:ssh_options) + ssh_opts[:forward_agent] = true + ssh_opts[:verbose] = false ## Contributing diff --git a/lib/capistrano/one_time_key.rb b/lib/capistrano/one_time_key.rb index 84c7295..ffaaf60 100644 --- a/lib/capistrano/one_time_key.rb +++ b/lib/capistrano/one_time_key.rb @@ -10,7 +10,7 @@ def self.tmpdir end def self.temporary_ssh_private_key_path - File.join(tmpdir, "capistrano_key") + @key_path ||= File.join(tmpdir, "capistrano_key") end def self.comment @@ -50,7 +50,7 @@ def self.add_key_to_host capistrano_host, public_key end def self.remove_key_from_host capistrano_host, public_key - execute_on_remote capistrano_host, "sed -i.bak -e '/#{comment}$/d' -e '/^$/d' ~/.ssh/authorized_keys && rm ~/.ssh/authorized_keys.bak" + execute_on_remote capistrano_host, "sed -i.bak -e '/#{comment}$/d' -e '/^\s*$/d' ~/.ssh/authorized_keys && rm ~/.ssh/authorized_keys.bak" end def self.execute_on_remote capistrano_host, command