Sha256: 4e36a73bff1e528755710072f356508bff4b0c80268ce1c69e2da4eda9fd94dd

Contents?: true

Size: 590 Bytes

Versions: 1

Compression:

Stored size: 590 Bytes

Contents

namespace :ssh do
  desc 'Adds public key to the authorized_keys file (to enable passwordless login)'
  task :add_key do
    ask(:key, 'SSH public key')
    on roles(:all) do |host|
      # this script depends on the HOME environment variable to be set
      home = capture("env | grep HOME").split('=').last
      within home do
        remote_keys = capture(:cat, '.ssh/authorized_keys')
        keys = remote_keys.split("\n")
        keys << fetch(:key) + "\n"
        new_keys = StringIO.new(keys.join("\n"))
        upload! new_keys, '.ssh/authorized_keys'
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
capistrano-devops-0.0.1 lib/capistrano/tasks/ssh.rake