diff --git a/CHANGELOG.md b/CHANGELOG.md index 5cb1a081f..6b6549baf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ - Provisioners will still mount folders and such if `--no-provision` is used, so that `vagrant provision` works. [GH-803] + - Nicer error message if an unsupported SSH key type is used. [GH-805] ## 1.0.1 (March 11, 2012) diff --git a/lib/vagrant/communication/ssh.rb b/lib/vagrant/communication/ssh.rb index e7d9fa7aa..feeac65c4 100644 --- a/lib/vagrant/communication/ssh.rb +++ b/lib/vagrant/communication/ssh.rb @@ -129,10 +129,24 @@ module Vagrant @vm.ssh.check_key_permissions(ssh_info[:private_key_path]) # Connect to SSH, giving it a few tries - @logger.info("Connecting to SSH: #{ssh_info[:host]}:#{ssh_info[:port]}") - exceptions = [Errno::ECONNREFUSED, Net::SSH::Disconnect] - connection = retryable(:tries => @vm.config.ssh.max_tries, :on => exceptions) do - Net::SSH.start(ssh_info[:host], ssh_info[:username], opts) + connection = nil + begin + @logger.info("Connecting to SSH: #{ssh_info[:host]}:#{ssh_info[:port]}") + exceptions = [Errno::ECONNREFUSED, Net::SSH::Disconnect] + connection = retryable(:tries => @vm.config.ssh.max_tries, :on => exceptions) do + Net::SSH.start(ssh_info[:host], ssh_info[:username], opts) + end + rescue Net::SSH::AuthenticationFailed + # This happens if authentication failed. We wrap the error in our + # own exception. + raise Errors::SSHAuthenticationFailed + rescue Errno::ECONNREFUSED + # This is raised if we failed to connect the max amount of times + raise Errors::SSHConnectionRefused + rescue NotImplementedError + # This is raised if a private key type that Net-SSH doesn't support + # is used. Show a nicer error. + raise Errors::SSHKeyTypeNotSupported end @connection = connection @@ -145,14 +159,7 @@ module Vagrant # Yield the connection that is ready to be used and # return the value of the block return yield connection if block_given? - rescue Net::SSH::AuthenticationFailed - # This happens if authentication failed. We wrap the error in our - # own exception. - raise Errors::SSHAuthenticationFailed - rescue Errno::ECONNREFUSED - # This is raised if we failed to connect the max amount of times - raise Errors::SSHConnectionRefused - end + end # Executes the command on an SSH connection within a login shell. def shell_execute(connection, command, sudo=false) diff --git a/lib/vagrant/errors.rb b/lib/vagrant/errors.rb index 6523216df..e234d76f8 100644 --- a/lib/vagrant/errors.rb +++ b/lib/vagrant/errors.rb @@ -318,6 +318,11 @@ module Vagrant error_key(:ssh_key_bad_permissions) end + class SSHKeyTypeNotSupported < VagrantError + status_code(76) + error_key(:ssh_key_type_not_supported) + end + class SSHPortNotDetected < VagrantError status_code(50) error_key(:ssh_port_not_detected) diff --git a/templates/locales/en.yml b/templates/locales/en.yml index 92b01a5b1..f4bb64860 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -124,6 +124,10 @@ en: permissions on the following file to 0600 and then try running this command again: %{key_path} + ssh_key_type_not_supported: |- + The private key you're attempting to use with this Vagrant box uses + an unsupported encryption type. The SSH library Vagrant uses does not support + this key type. Please use `ssh-rsa` or `ssh-dss` instead. ssh_port_not_detected: |- Vagrant couldn't determine the SSH port for your VM! Vagrant attempts to automatically find a forwarded port that matches your `config.ssh.guest_port`