Class: VagrantPlugins::GuestMSYS2::Cap::RemovePublicKey

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-guest-msys2/cap/remove_public_key.rb

Class Method Summary collapse

Class Method Details

.remove_public_key(machine, contents) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/vagrant-guest-msys2/cap/remove_public_key.rb', line 7

def self.remove_public_key(machine, contents)
  contents = contents.chomp
  contents = Vagrant::Util::ShellQuote.escape(contents, "'")

  machine.communicate.tap do |comm|
    if comm.test("test -f ~/.ssh/authorized_keys")
      comm.execute(<<SCRIPT)
sed -e '/^.*#{contents}.*$/d' ~/.ssh/authorized_keys > ~/.ssh/authorized_keys.new
mv ~/.ssh/authorized_keys.new ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
SCRIPT
    end
  end
end