title: setting up ssh passwordless in ec2 via chef
body: <p>I have the following <code>recipe/default.rb</code> in Chef:</p>
  
  <pre><code># Create empty RSA password
  template "#{node[:cluster][:ubuntu]}/my_key.pem" do
     source "keys.pem.erb"
     mode 0400
     owner "ubuntu"
     group "ubuntu"
  end
  
  bash "ssh-passwordless" do
     user "ubuntu"
     cwd "#{node[:cluster][:ubuntu]}"
     code &lt;&lt;-EOF
     eval `ssh-agent -s`
     ssh-add #{node[:cluster][:ubuntu]}/my_key.pem
     EOF
  end
  
  # Create empty RSA password
  execute "ssh-keygen" do
    command "sudo -u ubuntu ssh-keygen -q -t rsa -N '' -f /home/ubuntu/.ssh/id_rsa"
    creates "/home/ubuntu/.ssh/id_rsa"
   action :run
  end
  
  # Copy public key to node1; if key doesn't exist in authorized_keys, append it to this file
  execute &lt;&lt;EOF
  cat /home/ubuntu/.ssh/id_rsa.pub | sudo -u ubuntu ssh ubuntu@localhost "(cat &gt; /tmp/tmp.pubkey; mkdir -p .ssh; touch .ssh/authorized_keys; grep #{node[:fqdn]} .ssh/authorized_keys &gt; /dev/null || cat /tmp/tmp.pubkey &gt;&gt; .ssh/authorized_keys; rm /tmp/tmp.pubkey)
  </code></pre>
  
  <p>As you can see, I'm trying a lot of methods to get it to work, however, none of them have succeed so far. The goal is to remove the need of password / pem file in EC2, so I can set up a hadoop cluster. How can I accomplish that?</p>