Sha256: 5712c9bba47bbb79dbdc84211c8f10497df54f27a6b3c873d04f8dfa5da19f99

Contents?: true

Size: 649 Bytes

Versions: 17

Compression:

Stored size: 649 Bytes

Contents

module AwsEc2::Template::Helper::SshKeyHelper
  def add_ssh_key(user="ec2-user")
    key_path = "#{ENV['HOME']}/.ssh/id_rsa.pub"
    if File.exist?(key_path)
      public_key = IO.read(key_path).strip
    end
    if public_key
      <<-SCRIPT
# Automatically add user's public key from #{key_path}
cp /home/#{user}/.ssh/authorized_keys{,.bak}
echo #{public_key} >> /home/#{user}/.ssh/authorized_keys
chown #{user}:#{user} /home/#{user}/.ssh/authorized_keys
SCRIPT
    else
      <<-SCRIPT
# WARN: unable to find a ~/.ssh/id_rsa.pub locally on your machine.  user: #{ENV['USER']}
# Unable to automatically add the public key
SCRIPT
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
aws-ec2-1.4.9 lib/aws_ec2/template/helper/ssh_key_helper.rb
aws-ec2-1.4.8 lib/aws_ec2/template/helper/ssh_key_helper.rb
aws-ec2-1.4.7 lib/aws_ec2/template/helper/ssh_key_helper.rb
aws-ec2-1.4.6 lib/aws_ec2/template/helper/ssh_key_helper.rb
aws-ec2-1.4.5 lib/aws_ec2/template/helper/ssh_key_helper.rb
aws-ec2-1.4.4 lib/aws_ec2/template/helper/ssh_key_helper.rb
aws-ec2-1.4.3 lib/aws_ec2/template/helper/ssh_key_helper.rb
aws-ec2-1.4.2 lib/aws_ec2/template/helper/ssh_key_helper.rb
aws-ec2-1.4.1 lib/aws_ec2/template/helper/ssh_key_helper.rb
aws-ec2-1.4.0 lib/aws_ec2/template/helper/ssh_key_helper.rb
aws-ec2-1.3.2 lib/aws_ec2/template/helper/ssh_key_helper.rb
aws-ec2-1.3.1 lib/aws_ec2/template/helper/ssh_key_helper.rb
aws-ec2-1.3.0 lib/aws_ec2/template/helper/ssh_key_helper.rb
aws-ec2-1.2.2 lib/aws_ec2/template/helper/ssh_key_helper.rb
aws-ec2-1.2.1 lib/aws_ec2/template/helper/ssh_key_helper.rb
aws-ec2-1.2.0 lib/aws_ec2/template/helper/ssh_key_helper.rb
aws-ec2-1.1.0 lib/aws_ec2/template/helper/ssh_key_helper.rb