From e909b91bfd83c46520a0f51a1f27cefccf309211 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 12 Feb 2014 22:11:33 -0800 Subject: [PATCH] guests/linux: public key insertion is more robust contents can have newlines (or not) --- plugins/guests/linux/cap/insert_public_key.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/guests/linux/cap/insert_public_key.rb b/plugins/guests/linux/cap/insert_public_key.rb index f33e3329f..f238cd9a1 100644 --- a/plugins/guests/linux/cap/insert_public_key.rb +++ b/plugins/guests/linux/cap/insert_public_key.rb @@ -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