bbe722df9cbf5e7eb5dc25fa619ecfa47350b748
[vagrant-dotfiles.git] / lib / copy_my_conf / ssh.rb
1 module Vagrant
2 module Provisioners
3 class CopyMyConf < Base
4 class Ssh
5 def prepare vm, tmp_root
6 vm.share_folder("ssh", "#{tmp_root}/ssh", "~/.ssh")
7 end
8
9 def provision channel, user_home, tmp_root
10 puts "Copying your ssh keys and config"
11 channel.sudo("mkdir -p #{tmp_root}/cached && chown -R vagrant #{tmp_root}/cached")
12 channel.execute("[[ -f #{user_home}/.ssh/authorized_keys ]] && mv #{user_home}/.ssh/authorized_keys #{tmp_root}/cached")
13 channel.execute("cp #{tmp_root}/ssh/* #{user_home}/.ssh")
14 channel.execute("cat #{tmp_root}/cached/authorized_keys >> #{user_home}/.ssh/authorized_keys") # So that `vagrant ssh` doesn't ask for password
15 end
16
17 end
18 end
19 end
20 end