guests/linux: public key insertion is more robust

contents can have newlines (or not)
This commit is contained in:
Mitchell Hashimoto 2014-02-12 22:11:33 -08:00
parent 8bfb4bda2b
commit e909b91bfd
1 changed files with 2 additions and 2 deletions

View File

@ -5,13 +5,13 @@ module VagrantPlugins
module Cap
class InsertPublicKey
def self.insert_public_key(machine, contents)
contents = contents.chomp
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("printf '#{contents}\\n' >> ~/.ssh/authorized_keys")
comm.execute("chmod 0600 ~/.ssh/authorized_keys")
end
end