diff --git a/lib/vagrant-hostmanager/hosts_file/updater.rb b/lib/vagrant-hostmanager/hosts_file/updater.rb index 409cbf4..38e346d 100644 --- a/lib/vagrant-hostmanager/hosts_file/updater.rb +++ b/lib/vagrant-hostmanager/hosts_file/updater.rb @@ -62,7 +62,12 @@ class << self copy_proc = Proc.new { windows_copy_file(file, hosts_location) } else hosts_location = '/etc/hosts' - copy_proc = Proc.new { `[ -w #{hosts_location} ] && cat #{file} > #{hosts_location} || sudo cp #{file} #{hosts_location}` } + if !ENV['SUDO_ASKPASS'].nil? + sudo='sudo -A' + else + sudo='sudo' + end + copy_proc = Proc.new { `[ -w #{hosts_location} ] && cat #{file} > #{hosts_location} || #{sudo} cp #{file} #{hosts_location}` } end FileUtils.cp(hosts_location, file)