diff --git a/plugins/communicators/ssh/communicator.rb b/plugins/communicators/ssh/communicator.rb index 56525a40b..3d3d5a4b8 100644 --- a/plugins/communicators/ssh/communicator.rb +++ b/plugins/communicators/ssh/communicator.rb @@ -196,8 +196,13 @@ module VagrantPlugins # Adjust private key file permissions if Vagrant::Util::Platform.windows? - priv_path = @machine.data_dir.join("private_key").to_s - File.set_permissions(priv_path, Etc.getlogin => File::FULL) + begin + priv_path = @machine.data_dir.join("private_key").to_s + File.set_permissions(priv_path, Etc.getlogin => File::FULL) + rescue => e + @logger.warn("Error encountered during private key permissions set - " \ + "#{e.class}: #{e.message}") + end else @machine.data_dir.join("private_key").chmod(0600) end diff --git a/test/unit/plugins/communicators/ssh/communicator_test.rb b/test/unit/plugins/communicators/ssh/communicator_test.rb index 8f8f88806..1b244b8a3 100644 --- a/test/unit/plugins/communicators/ssh/communicator_test.rb +++ b/test/unit/plugins/communicators/ssh/communicator_test.rb @@ -231,6 +231,10 @@ describe VagrantPlugins::CommunicatorSSH::Communicator do expect(File).to receive(:set_permissions).with("PRIVATE_KEY_PATH", any_args) end + it "should proceed when error is encountered" do + expect(File).to receive(:set_permissions).and_raise(StandardError) + end + context "with multiple permissions on file" do it "should delete all non-owner permissions" do