vaguerent/plugins/guests/openbsd/cap/insert_public_key.rb
Teemu Matilainen c11820c848 guests/openbsd: Add back insert_public_key cap
Copied from linux guest.
2014-02-03 08:29:54 -03:00

22 lines
620 B
Ruby

require "vagrant/util/shell_quote"
module VagrantPlugins
module GuestOpenBSD
module Cap
class InsertPublicKey
def self.insert_public_key(machine, contents)
contents = Vagrant::Util::ShellQuote.escape(contents, "'")
contents = contents.gsub("\n", "\\n")
machine.communicate.tap do |comm|
comm.execute("mkdir -p ~/.ssh")
comm.execute("chmod 0700 ~/.ssh")
comm.execute("printf '#{contents}' >> ~/.ssh/authorized_keys")
comm.execute("chmod 0600 ~/.ssh/authorized_keys")
end
end
end
end
end
end