Vagrant ssh'身份验证失败.重试...'重复错误 - 密钥不匹配,无法找到修复

Kar*_*eem 5 ssh hyper-v openssh vagrant windows-10

我一直在经历一个令人烦恼的问题,我无法绕过.

我正在尝试vagrant up在这种环境中使用centos7系统:

  • Windows 10
  • Hyper-V(不是周年纪念更新版)
  • Docker图片"serveit/centos-7"或"bluefedora/hyperv-alpha-centos7"
  • 安装了OpenSSH,配置了私钥

我的Vagrantfile的内容:

Vagrant.configure("2") do |config|
  #config.vm.box = "serveit/centos-7"
  config.vm.box = "bluefedora/hyperv-alpha-centos7"
  config.ssh.private_key_path = "~/.vagrant.d/insecure_private_key"
  config.ssh.forward_agent = true
end
Run Code Online (Sandbox Code Playgroud)

我在做一个时遇到这个错误vagrant up:

PS C:\Programs\vagrant_stuff\centos7> vagrant up
Bringing machine 'default' up with 'hyperv' provider...
==> default: Verifying Hyper-V is enabled...
==> default: Importing a Hyper-V instance
    default: Cloning virtual hard drive...
    default: Creating and registering the VM...
    default: Successfully imported a VM with name: vagrantbox
==> default: Starting the machine...
==> default: Waiting for the machine to report its IP address...
    default: Timeout: 120 seconds
    default: IP: 192.168.137.6
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 192.168.137.6:22
    default: SSH username: vagrant
    default: SSH auth method: private key
    default:
    default: Vagrant insecure key detected. Vagrant will automatically replace
    default: this with a newly generated keypair for better security.
    default:
    default: Inserting generated public key within guest...
    default: Removing insecure key from the guest if it's present...
    default: Key inserted! Disconnecting and reconnecting using new SSH key...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
Timed out while waiting for the machine to boot. This means that
Vagrant was unable to communicate with the guest machine within
the configured ("config.vm.boot_timeout" value) time period.

If you look above, you should be able to see the error(s) that
Vagrant had when attempting to connect to the machine. These errors
are usually good hints as to what may be wrong.

If you're using a custom box, make sure that networking is properly
working and you're able to connect to the machine. It is a common
problem that networking isn't setup properly in these boxes.
Verify that authentication configurations are also setup properly,
as well.

If the box appears to be booting properly, you may want to increase
the timeout ("config.vm.boot_timeout") value.
Run Code Online (Sandbox Code Playgroud)

我可以做一个vagrant ssh-config:

Host default
  HostName 192.168.137.6
  User vagrant
  Port 22
  UserKnownHostsFile /dev/null
  StrictHostKeyChecking no
  PasswordAuthentication no
  IdentityFile C:/Users/Kareem/.vagrant.d/insecure_private_key
  IdentitiesOnly yes
  LogLevel FATAL
  ForwardAgent yes
Run Code Online (Sandbox Code Playgroud)

我看到其他地方我应该尝试vagrant haltvagrant up解决这个问题.这没用.

我也删除了.vagrant.d/insecure_private_key文件,看到它被重新创建.没问题,这也是预期的.

vagrant ssh适用于密码:

PS C:\Programs\vagrant_stuff\centos7> vagrant ssh
vagrant@192.168.137.6's password:
[vagrant@localhost ~]$
Run Code Online (Sandbox Code Playgroud)

因为我可以通过SSH,我决定检查.ssh/authorized_keys文件:

[vagrant @ localhost~] $ cat .ssh/authorized_keys

[vagrant@localhost ~]$ cat /home/vagrant/.ssh/authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDIRcYs0HBn/BOjiKg9fGnoraVxRnnZk+6sM3waFFE1+U3aO8GQjRKxQsYgJNoyRmNVymzpP13kOoLodDsz
UKhdcO6dL+zAtmhsFTgmADMXxVzM3mfRWfPG2HdsU13Pof77A68Ln6z6X4jVG4cnsclYvz67Gudl7lZ9VI2TOdDn1V+7ZANlkGnqejIwA2RVWtYLgLQHU9p4
47nvRqId71XaG8BZpbONRzzrL49wWyjfc4h6SdaHVJZJB6kY+vkr31xw6TPIIlo2UHH7Ihlk6KADNo4wFJYF+ozIA7C792omzjN1zu1SayvCYNG21yZy/cCd
n2Hr158Jy83A9CslQPbT vagrant
Run Code Online (Sandbox Code Playgroud)

Dafuq是关键吗?!?! 我很确定这不是与Vagrant相对应的公钥.这也不是我的系统公钥.当我检查 Vagrant公钥时,我得到了这个:

ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9H
ZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHi
lFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRd
K8jlqm8tehUc9c9WhQ== vagrant insecure public key
Run Code Online (Sandbox Code Playgroud)

此外,如果我更新我Vagrantfile使用我的系统私钥:

  #config.ssh.private_key_path = "~/.vagrant.d/insecure_private_key"
  config.ssh.private_key_path = "~/.ssh/id_rsa"
Run Code Online (Sandbox Code Playgroud)

我在VM中获得了一个不同的公钥,即Vagrant公钥:

[vagrant@localhost ~]$ cat /home/vagrant/.ssh/authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9H
ZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHi
lFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRd
K8jlqm8tehUc9c9WhQ== vagrant insecure public key
Run Code Online (Sandbox Code Playgroud)

我还看到配置过程没有插入新密钥.这一切似乎都倒退了,我认为只有在我使用私钥时才能更新密钥,并且它应该使用我自己的密钥.

救命!

任何人都可以帮我找出为什么会这样吗?

Kar*_*eem 7

事实证明,Vag​​rant 1.8.5中存在一个已知错误(将在1.8.6中修复):

细节在这里

如果您使用的是1.8.5,则可以使用PowerShell 从PR #7611下载更新版本:

[IO.File]::WriteAllLines("C:\HashiCorp\Vagrant\embedded\gems\gems\vagrant-1.8.5\plugins\guests\linux\cap\public_key.rb", (Invoke-WebRequest -Uri https://raw.githubusercontent.com/Poohblah/vagrant/41063204ca540c44f9555bd11ba9e76c7307bec5/plugins/guests/linux/cap/public_key.rb).Content)

  • 从那里的评论中,我了解到Mac上的补丁文件是`/ opt/vagrant/embedded/gems/gems/vagrant-1.8.5/plugins/guests/linux/cap/public_key.rb`.(差异内容在链接中给出.)该补丁后一切正常. (2认同)