2014-01-03 19:13:21 +00:00
|
|
|
module VagrantPlugins
|
|
|
|
module GuestLinux
|
|
|
|
module Cap
|
|
|
|
class InsertPublicKey
|
|
|
|
def self.insert_public_key(machine, contents)
|
2016-06-05 18:49:59 +00:00
|
|
|
comm = machine.communicate
|
2016-06-16 10:47:47 +00:00
|
|
|
contents = contents.chomp+"\n"
|
2014-01-08 23:12:26 +00:00
|
|
|
|
2016-06-05 18:49:59 +00:00
|
|
|
remote_path = "/tmp/vagrant-authorized-keys-#{Time.now.to_i}"
|
|
|
|
Tempfile.open("vagrant-linux-insert-public-key") do |f|
|
|
|
|
f.binmode
|
|
|
|
f.write(contents)
|
|
|
|
f.fsync
|
|
|
|
f.close
|
|
|
|
comm.upload(f.path, remote_path)
|
2014-01-03 19:13:21 +00:00
|
|
|
end
|
2016-06-05 18:49:59 +00:00
|
|
|
|
|
|
|
comm.execute <<-EOH.gsub(/^ {12}/, '')
|
|
|
|
mkdir -p ~/.ssh
|
|
|
|
chmod 0700 ~/.ssh
|
|
|
|
cat '#{remote_path}' >> ~/.ssh/authorized_keys
|
|
|
|
chmod 0600 ~/.ssh/authorized_keys
|
|
|
|
|
|
|
|
# Remove the temporary file
|
|
|
|
rm -f '#{remote_path}'
|
|
|
|
EOH
|
2014-01-03 19:13:21 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|