From f7f46ba47de40905a92884923780e5cbca9790b2 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Wed, 15 Jun 2016 23:56:22 +0100 Subject: [PATCH 1/3] Append newline to each key added The change to this file 10 days ago removed a newline character at the end of each key added to it. This mean that when another key was added, it continued on the same line as the one before and thus wasn't being detected when an ssh connection came in with a key file. With regards to https://github.com/mitchellh/vagrant/issues/7455 this is an (ugly) fix. I'm sure someone knows a better command to concat a file and a string and append it to the `authorized_keys` file. But this does fix the problem. --- plugins/guests/linux/cap/insert_public_key.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/guests/linux/cap/insert_public_key.rb b/plugins/guests/linux/cap/insert_public_key.rb index b7335bdc5..8fee49a12 100644 --- a/plugins/guests/linux/cap/insert_public_key.rb +++ b/plugins/guests/linux/cap/insert_public_key.rb @@ -19,6 +19,7 @@ module VagrantPlugins mkdir -p ~/.ssh chmod 0700 ~/.ssh cat '#{remote_path}' >> ~/.ssh/authorized_keys + echo "\n" >> ~/.ssh/authorized_keys chmod 0600 ~/.ssh/authorized_keys # Remove the temporary file From 2720ed3d2c8e43adf5d5527a44aad4daa1ccc1cf Mon Sep 17 00:00:00 2001 From: Jonathan Date: Thu, 16 Jun 2016 11:47:47 +0100 Subject: [PATCH 2/3] Apply new line before shell to system Having looked at the code again this seems like a more straightforward way of fixing the bug. --- plugins/guests/linux/cap/insert_public_key.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugins/guests/linux/cap/insert_public_key.rb b/plugins/guests/linux/cap/insert_public_key.rb index 8fee49a12..4cda1c0e0 100644 --- a/plugins/guests/linux/cap/insert_public_key.rb +++ b/plugins/guests/linux/cap/insert_public_key.rb @@ -4,7 +4,7 @@ module VagrantPlugins class InsertPublicKey def self.insert_public_key(machine, contents) comm = machine.communicate - contents = contents.chomp + contents = contents.chomp+"\n" remote_path = "/tmp/vagrant-authorized-keys-#{Time.now.to_i}" Tempfile.open("vagrant-linux-insert-public-key") do |f| @@ -19,7 +19,6 @@ module VagrantPlugins mkdir -p ~/.ssh chmod 0700 ~/.ssh cat '#{remote_path}' >> ~/.ssh/authorized_keys - echo "\n" >> ~/.ssh/authorized_keys chmod 0600 ~/.ssh/authorized_keys # Remove the temporary file From d1be7ae84a9858095054124f891cea487194d81c Mon Sep 17 00:00:00 2001 From: Jonathan Date: Thu, 16 Jun 2016 11:59:11 +0100 Subject: [PATCH 3/3] Better method for string concatenation Never developed in Ruby before. I have only just discovered that apparently `<<` is a better method of string concatenation. --- plugins/guests/linux/cap/insert_public_key.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/guests/linux/cap/insert_public_key.rb b/plugins/guests/linux/cap/insert_public_key.rb index 4cda1c0e0..08edb90ae 100644 --- a/plugins/guests/linux/cap/insert_public_key.rb +++ b/plugins/guests/linux/cap/insert_public_key.rb @@ -4,7 +4,7 @@ module VagrantPlugins class InsertPublicKey def self.insert_public_key(machine, contents) comm = machine.communicate - contents = contents.chomp+"\n" + contents = contents.chomp << "\n" remote_path = "/tmp/vagrant-authorized-keys-#{Time.now.to_i}" Tempfile.open("vagrant-linux-insert-public-key") do |f|