diff --git a/lib/vagrant/ssh.rb b/lib/vagrant/ssh.rb index c68c93e40..2f5f8ec55 100644 --- a/lib/vagrant/ssh.rb +++ b/lib/vagrant/ssh.rb @@ -42,6 +42,9 @@ module Vagrant # Opens an SSH connection to this environment's virtual machine and yields # a Net::SSH object which can be used to execute remote commands. def execute(opts={}) + # Check the key permissions to avoid SSH hangs + check_key_permissions(env.config.ssh.private_key_path) + Net::SSH.start(env.config.ssh.host, env.config[:ssh][:username], opts.merge( :port => port, diff --git a/test/vagrant/ssh_test.rb b/test/vagrant/ssh_test.rb index 306c81cd4..ce95ad0e9 100644 --- a/test/vagrant/ssh_test.rb +++ b/test/vagrant/ssh_test.rb @@ -85,6 +85,14 @@ class SshTest < Test::Unit::TestCase context "executing ssh commands" do setup do mock_ssh + @ssh.stubs(:check_key_permissions) + end + + should "check key permissions then attempt to start connection" do + seq = sequence("seq") + @ssh.expects(:check_key_permissions).with(@env.config.ssh.private_key_path).once.in_sequence(seq) + Net::SSH.expects(:start).once.in_sequence(seq) + @ssh.execute end should "call net::ssh.start with the proper names" do @@ -123,6 +131,7 @@ class SshTest < Test::Unit::TestCase context "checking if host is up" do setup do mock_ssh + @ssh.stubs(:check_key_permissions) end should "return true if SSH connection works" do