diff --git a/plugins/guests/freebsd/cap/insert_public_key.rb b/plugins/guests/freebsd/cap/insert_public_key.rb new file mode 100644 index 000000000..5fc414d39 --- /dev/null +++ b/plugins/guests/freebsd/cap/insert_public_key.rb @@ -0,0 +1,21 @@ +require "vagrant/util/shell_quote" + +module VagrantPlugins + module GuestFreeBSD + 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", shell: "sh") + comm.execute("chmod 0700 ~/.ssh", shell: "sh") + comm.execute("printf '#{contents}' >> ~/.ssh/authorized_keys", shell: "sh") + comm.execute("chmod 0600 ~/.ssh/authorized_keys", shell: "sh") + end + end + end + end + end +end diff --git a/plugins/guests/freebsd/plugin.rb b/plugins/guests/freebsd/plugin.rb index 50f82bea2..8136adfdf 100644 --- a/plugins/guests/freebsd/plugin.rb +++ b/plugins/guests/freebsd/plugin.rb @@ -26,6 +26,11 @@ module VagrantPlugins Cap::Halt end + guest_capability("freebsd", "insert_public_key") do + require_relative "cap/insert_public_key" + Cap::InsertPublicKey + end + guest_capability("freebsd", "mount_nfs_folder") do require_relative "cap/mount_nfs_folder" Cap::MountNFSFolder diff --git a/plugins/guests/netbsd/cap/insert_public_key.rb b/plugins/guests/netbsd/cap/insert_public_key.rb new file mode 100644 index 000000000..dadce0f56 --- /dev/null +++ b/plugins/guests/netbsd/cap/insert_public_key.rb @@ -0,0 +1,21 @@ +require "vagrant/util/shell_quote" + +module VagrantPlugins + module GuestNetBSD + 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 diff --git a/plugins/guests/netbsd/plugin.rb b/plugins/guests/netbsd/plugin.rb index 97fcf952f..ef822e4d4 100644 --- a/plugins/guests/netbsd/plugin.rb +++ b/plugins/guests/netbsd/plugin.rb @@ -26,6 +26,11 @@ module VagrantPlugins Cap::Halt end + guest_capability("netbsd", "insert_public_key") do + require_relative "cap/insert_public_key" + Cap::InsertPublicKey + end + guest_capability("netbsd", "mount_nfs_folder") do require_relative "cap/mount_nfs_folder" Cap::MountNFSFolder