lib/deprec/recipes/ssh.rb in deprec-2.0.1 vs lib/deprec/recipes/ssh.rb in deprec-2.0.2

- old
+ new

@@ -60,33 +60,51 @@ Capistrano::CLI.ui.ask "Setup keys for which user?" do |q| q.default = user end } - if target_user == user + # If we have an authorized keys file for this user + # then copy that out + if File.exists?("config/ssh/authorized_keys/#{target_user}") + deprec2.mkdir "/home/#{target_user}/.ssh", :mode => 0700, :owner => "#{target_user}.users", :via => :sudo + std.su_put File.read("config/ssh/authorized_keys/#{target_user}"), "/home/#{target_user}/.ssh/authorized_keys", '/tmp/', :mode => 0600 + sudo "chown #{target_user}.users /home/#{target_user}/.ssh/authorized_keys" + + elsif target_user == user - unless ssh_options[:keys] + # If the user has specified a key Capistrano should use + if ssh_options[:keys] + deprec2.mkdir '.ssh', :mode => 0700 + put(ssh_options[:keys].collect{|key| File.read(key)}.join("\n"), '.ssh/authorized_keys', :mode => 0600 ) + + # Try to find the current users public key + elsif keys = %w[id_rsa id_dsa identity].collect { |f| "#{ENV['HOME']}/.ssh/#{f}.pub" if File.exists?("#{ENV['HOME']}/.ssh/#{f}.pub") }.compact + deprec2.mkdir '.ssh', :mode => 0700 + put(keys.collect{|key| File.read(key)}.join("\n"), '.ssh/authorized_keys', :mode => 0600 ) + + else puts <<-ERROR You need to define the name of your SSH key(s) e.g. ssh_options[:keys] = %w(/Users/your_username/.ssh/id_rsa) You can put this in your .caprc file in your home directory. ERROR exit end - - deprec2.mkdir '.ssh', :mode => 0700 - put(ssh_options[:keys].collect{|key| File.read(key+'.pub')}.join("\n"), '.ssh/authorized_keys', :mode => 0600 ) + else + puts <<-ERROR - else + Could not find ssh public key(s) for user #{user} - deprec2.mkdir "/home/#{target_user}/.ssh", :mode => 0700, :owner => "#{target_user}.users", :via => :sudo - std.su_put File.read("config/ssh/authorized_keys/#{target_user}"), "/home/#{target_user}/.ssh/authorized_keys", '/tmp/', :mode => 0600 - sudo "chown #{target_user}.users /home/#{target_user}/.ssh/authorized_keys" + Please create file containing ssh public keys in: + config/ssh/authorized_keys/#{target_user} + + ERROR end + end end end end \ No newline at end of file