guests/linux: public key insertion is more robust
contents can have newlines (or not)
This commit is contained in:
parent
8bfb4bda2b
commit
e909b91bfd
|
@ -5,13 +5,13 @@ module VagrantPlugins
|
||||||
module Cap
|
module Cap
|
||||||
class InsertPublicKey
|
class InsertPublicKey
|
||||||
def self.insert_public_key(machine, contents)
|
def self.insert_public_key(machine, contents)
|
||||||
|
contents = contents.chomp
|
||||||
contents = Vagrant::Util::ShellQuote.escape(contents, "'")
|
contents = Vagrant::Util::ShellQuote.escape(contents, "'")
|
||||||
contents = contents.gsub("\n", "\\n")
|
|
||||||
|
|
||||||
machine.communicate.tap do |comm|
|
machine.communicate.tap do |comm|
|
||||||
comm.execute("mkdir -p ~/.ssh")
|
comm.execute("mkdir -p ~/.ssh")
|
||||||
comm.execute("chmod 0700 ~/.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")
|
comm.execute("chmod 0600 ~/.ssh/authorized_keys")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue