guests/linux: properly quote and insert public key
This commit is contained in:
parent
880281f27f
commit
732a03c1c4
|
@ -63,7 +63,7 @@ module VagrantPlugins
|
|||
@machine.ui.info(I18n.t("vagrant.inserting_insecure_key"))
|
||||
@machine.guest.capability(
|
||||
:insert_public_key,
|
||||
Vagrant.source_root.join("keys", "vagrant.pub").read)
|
||||
Vagrant.source_root.join("keys", "vagrant.pub").read.chomp)
|
||||
|
||||
# Write out the private key in the data dir so that the
|
||||
# machine automatically picks it up.
|
||||
|
|
|
@ -1,13 +1,17 @@
|
|||
require "vagrant/util/shell_quote"
|
||||
|
||||
module VagrantPlugins
|
||||
module GuestLinux
|
||||
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("echo #{contents} > /tmp/key.pub")
|
||||
comm.execute("mkdir -p ~/.ssh")
|
||||
comm.execute("chmod 0700 ~/.ssh")
|
||||
comm.execute("cat /tmp/key.pub >> ~/.ssh/authorized_keys")
|
||||
comm.execute("printf '#{contents}' >> ~/.ssh/authorized_keys")
|
||||
comm.execute("chmod 0600 ~/.ssh/authorized_keys")
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue