Class: CopyMyConf::Ssh

Inherits:
Object
  • Object
show all
Defined in:
lib/copy_my_conf/ssh.rb

Instance Method Summary collapse

Instance Method Details

#prepare(vm, tmp_root) ⇒ Object



3
4
5
# File 'lib/copy_my_conf/ssh.rb', line 3

def prepare vm, tmp_root
  vm.synced_folder("#{ENV['HOME']}/.ssh", "#{tmp_root}/ssh",:id => "ssh")
end

#provision(channel, user_home, tmp_root) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/copy_my_conf/ssh.rb', line 7

def provision channel, user_home, tmp_root
  puts "Copying your ssh keys and config"
  channel.sudo("mkdir -p #{tmp_root}/cached && chown -R vagrant #{tmp_root}/cached")
  channel.execute("[[ -f #{user_home}/.ssh/authorized_keys ]] && mv #{user_home}/.ssh/authorized_keys #{tmp_root}/cached")
  channel.execute("cp #{tmp_root}/ssh/* #{user_home}/.ssh")
  channel.execute("cat #{tmp_root}/cached/authorized_keys >> #{user_home}/.ssh/authorized_keys") # So that `vagrant ssh` doesn't ask for password
end