简体   繁体   English

Vagrant 冻结(超时)在 SSH 验证方法:私钥

[英]Vagrant freezes (timeouts) at SSH auth method: private key

So - i googled this and found about 1 Million Issues regarding vagrant provisioning and ssh agents.所以 - 我在谷歌上搜索了一下,发现了大约 100 万个关于 vagrant 供应和 ssh 代理的问题。 I tried lots of solutions and nothing works.我尝试了很多解决方案,但没有任何效果。 I tried adding options for the.network adaptor (VirtualBox), destroying the machine, reinstalling vagrant and so on, everytime i need to run vagrant this thing blocks me from working.我尝试为 .network 适配器 (VirtualBox) 添加选项,破坏机器,重新安装 vagrant 等等,每次我需要运行 vagrant 时,这个东西都会阻止我工作。

Now i work on a completely fresh OS Installation (Ubuntu 20.04).现在我致力于全新的操作系统安装(Ubuntu 20.04)。 I install VirtualBox 6.1 like instructed on the oracle website and downloaded the right vagrant binary from vagrantup.com/downloads.我按照 oracle 网站上的说明安装了 VirtualBox 6.1,并从 vagrantup.com/downloads 下载了正确的 vagrant 二进制文件。

And again - vagrant manages it to fail right-away, So okay - lets face it - vagrant is buggy and should be replaced but there are projects where i wont get any budget to migrate to containers, so i need to make that setup work again - and hopefuly someone has a solution for me.再次 - vagrant 管理它立即失败,好吧 - 让我们面对现实 - vagrant 有问题,应该更换,但有些项目我不会得到任何预算来迁移到容器,所以我需要使该设置再次工作- 希望有人能为我提供解决方案。 that actually works.这确实有效。

Okay - here the final vagrant up output:好的 - 这是最后的vagrant up output:

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.

So the machine runs but vagrant was not able to connect and run the provisioning.因此机器运行但 vagrant 无法连接并运行配置。 It basically downloaded the image and started it.它基本上下载了图像并启动了它。

So i try vagrant ssh --debug所以我尝试vagrant ssh --debug

The last lines i see:我看到的最后几行:

Checking key permissions: ~/.vagrant.d/insecure_private_key
 INFO ssh: Invoking SSH: /tmp/.mount_vagran2MLjJR/usr/bin/ssh ["vagrant@127.0.0.1", "-p", "2222", "-o", "LogLevel=FATAL", "-o", "Compression=yes", "-o", "DSAAuthentication=yes", "-o", "IdentitiesOnly=yes", "-o", "StrictHostKeyChecking=no", "-o", "UserKnownHostsFile=/dev/null", "-i", "~/.vagrant.d/insecure_private_key"]

And thats it - the command will fail without further notice.就是这样 - 命令将失败,恕不另行通知。

So i can only kill the vm (shutdown using vagrant halt wont work either:) and try to get more logs:所以我只能杀死虚拟机(关闭使用 vagrant 停止也不会工作:) 并尝试获取更多日志:

(just to make sure i re-installed the vbguest plugin) (只是为了确保我重新安装了 vbguest 插件)

vagrant up --debug

Okay - the screen-output looks like a loop.好的 - 屏幕输出看起来像一个循环。 And i can only find "Attemping SSH connection..." with the given options (path to key, etc)而且我只能找到具有给定选项(密钥路径等)的“正在尝试连接 SSH...”

After a few minutes (i gues the configured timeout) i can see:几分钟后(我猜是配置的超时)我可以看到:

INFO interface: Machine: error-exit ["Vagrant::Errors::VMBootTimeout", "Timed out while waiting for the machine to boot. This means that\nVagrant was unable to communicate with the guest machine within\nthe configured (\"config.vm.boot_timeout\" value) time period.\n\nIf you look above, you should be able to see the error(s) that\nVagrant had when attempting to connect to the machine. These errors\nare usually good hints as to what may be wrong.\n\nIf you're using a custom box, make sure that networking is properly\nworking and you're able to connect to the machine. It is a common\nproblem that networking isn't setup properly in these boxes.\nVerify that authentication configurations are also setup properly,\nas well.\n\nIf the box appears to be booting properly, you may want to increase\nthe timeout (\"config.vm.boot_timeout\") value."]

Here is some config:这是一些配置:

unless Vagrant.has_plugin?("vagrant-vbguest")
  raise 'vagrant-vbguest is not installed, see README.md!'
end
unless Vagrant.has_plugin?("vagrant-disksize")
  raise 'vagrant-disksize is not installed, see README.md!'
end
Vagrant.configure("2") do |config|
  # https://docs.vagrantup.com
  config.vm.box = "ubuntu/bionic64"
  config.disksize.size = "25GB"

  # forward http traffic
  config.vm.network "forwarded_port", guest: 80, host: 8083
  # forward mysql
  config.vm.network "forwarded_port", guest: 3306, host: 3308
  # forward xdebug
  config.vm.network "forwarded_port", guest: 9000, host: 9000
  # forward elastic
  config.vm.network "forwarded_port", guest: 9200, host: 9200
  # forward solr
  config.vm.network "forwarded_port", guest: 8983, host: 8983

  config.vm.synced_folder ".", "/vagrant",
    type: "virtualbox",
    id: "vagrant-root",
    owner: "vagrant",
    group: "www-data",
    mount_options: ["dmode=775,fmode=664"]

  config.vm.provider "virtualbox" do |vb|
    vb.memory = "8192"
    vb.cpus = 4
    vb.customize [ "modifyvm", :id, "--uartmode1", "disconnected" ]
    vb.customize [ "modifyvm", :id, "--cableconnected1", "on" ]
  end

  config.vm.provision "shell", path: "config/bootstrap.sh"
  config.vm.provision "shell", path: "config/solr.sh"
  config.vm.provision "shell", path: "config/startup.sh", run: "always"

end

My problem is - i have no idea how to solve this.我的问题是 - 我不知道如何解决这个问题。 I would be happy if i could disable the ssh authentication or use a password but i would need to connect to the vm to change it... Even if i could login using virtualbox i would only be able to fix my local installation.如果我可以禁用 ssh 身份验证或使用密码,我会很高兴,但我需要连接到虚拟机才能更改它……即使我可以使用 virtualbox 登录,我也只能修复我的本地安装。 But there are other people as well working on that code and a solution should fix this.但是还有其他人也在处理该代码,解决方案应该可以解决这个问题。

Just to sum this up once more:再次总结一下:

We deal with:我们处理:

  • A standard Ubuntu 20.04一标Ubuntu 20.04
  • A standard VirtualBox Installation标准的 VirtualBox 安装
  • A original vagrant binary一个原始的 vagrant 二进制文件

Fresh installation全新安装

wont work不会工作

Kind regards, Philipp亲切的问候,菲利普

Okay, by adding the following lines (referenced here: https://github.com/hashicorp/vagrant/issues/11777 ), i can successfully run the provisioning and ssh into the machine.好的,通过添加以下几行(此处引用: https : //github.com/hashicorp/vagrant/issues/11777 ),我可以成功地将配置和 ssh 运行到机器中。

config.vm.provider :virtualbox do |v|
  v.customize ["modifyvm", :id, "--uart1", "0x3F8", "4"]
  v.customize ["modifyvm", :id, "--uartmode1", "file", File::NULL]
end

So what you seem to need (at the moment - i am 100% sure that the next ssh issue with vagrant is only months away):所以你似乎需要什么(目前 - 我 100% 确定下一个 vagrant 的 ssh 问题只有几个月的时间):

Vagrant.configure("2") do |config|
  config.vm.provider "virtualbox" do |vb|
    vb.customize [ "modifyvm", :id, "--uartmode1", "file", File::NULL ]
    vb.customize [ "modifyvm", :id, "--uart1", "0x3F8", "4" ]
    vb.customize [ "modifyvm", :id, "--cableconnected1", "on" ]
  end
end

I noticed that the option vb.customize [ "modifyvm", :id, "--uartmode1", "file", File::NULL ] was already set with a different value ( vb.customize [ "modifyvm", :id, "--uartmode1", "disconnected" ] ) and dont know if you can assign multiple values or the original option caused the problem.我注意到选项vb.customize [ "modifyvm", :id, "--uartmode1", "file", File::NULL ]已经设置为不同的值 ( vb.customize [ "modifyvm", :id, "--uartmode1", "disconnected" ] ) 并且不知道您是否可以分配多个值或原始选项导致问题。 So i cant tell more for sure, if someone has more insights on this, a additional explanation would be great.所以我不能肯定地说更多,如果有人对此有更多见解,额外的解释会很棒。

My version looks like (only the relevant lines):我的版本看起来像(只有相关的行):

Vagrant.configure("2") do |config|
  config.vm.provider "virtualbox" do |vb|
    vb.customize [ "modifyvm", :id, "--uartmode1", "disconnected" ]
    vb.customize [ "modifyvm", :id, "--uartmode1", "file", File::NULL ]
    vb.customize [ "modifyvm", :id, "--uart1", "0x3F8", "4" ]
    vb.customize [ "modifyvm", :id, "--cableconnected1", "on" ]
  end
end

I have experienced the same problem on a couple of VMs of mine:我在我的几个虚拟机上遇到了同样的问题:

Vagrant + VirtualBox and (1) with CentOS 7 and (2) Ubuntu 18.04 images. Vagrant + VirtualBox和 (1) CentOS 7和 (2) Ubuntu 18.04图片。

Interestingly, the CentOS 7 VM was working fine previously with port forwarding for port 22 on the guest with port 2229 on the host.有趣的是, CentOS 7 VM 之前在主机上使用端口2229来宾上的端口22进行端口转发时运行良好。

TLDR: remapping the port forward on my VM resolved the problem with my Ubuntu VM, so I'm sharing that tip here. TLDR:在我的 VM 上重新映射端口转发解决了我的 Ubuntu VM 的问题,所以我在这里分享这个技巧。

TLDR2: Docker for Windows caused other issues, that I resolved by removing all trace of Windows-related virtualisation ( taking a sledgehammer to a screwdriver task ). TLDR2: Docker for Windows引起了其他问题,我通过删除所有与 Windows 相关的虚拟化痕迹(用大锤来完成螺丝刀任务)解决了这些问题。

The LONG story:长话短说:

On the CentOS VM, vagrant ssh-config showed:CentOS VM 上, vagrant ssh-config显示:

  HostName 127.0.0.1
  User vagrant
  Port 2229
  UserKnownHostsFile /dev/null
  StrictHostKeyChecking no
  PasswordAuthentication no
  IdentityFile "[[[REDACTED]]]/.vagrant/machines/default/virtualbox/private_key"
  IdentitiesOnly yes
  LogLevel FATAL

The notable line for me was IdentityFile showed private_key , which indicated that historically the private key was set up successfully.对我来说值得注意的是IdentityFile showed private_key ,这表明历史上私钥已成功设置。

However when I discovered this issue with my new Ubuntu VM, I returned to the CentOS VM and discovered that on a vagrant up it was also now timing out at SSH auth method: private key , suggesting that something has changed on my system or with VirtualBox during an update (I am already running the latest Vagrant available now, v2.2.19 ).然而,当我发现我的新 Ubuntu VM 存在这个问题时,我返回到 CentOS VM 并发现在vagrant up它现在也在SSH auth method: private key ,这表明我的系统或 VirtualBox 发生了一些变化在更新期间(我已经在运行现在可用的最新 Vagrant, v2.2.19 )。

I checked my new Ubuntu VM, where vagrant ssh-config showed:我检查了我的新 Ubuntu VM,其中vagrant ssh-config显示:

Host default
  HostName 127.0.0.1
  User vagrant
  Port 2222
  UserKnownHostsFile /dev/null
  StrictHostKeyChecking no
  PasswordAuthentication no
  IdentityFile [[[REDACTED]]]/.vagrant.d/insecure_private_key
  IdentitiesOnly yes
  LogLevel FATAL

and I noted that IdentityFile was insecure_private_key .我注意到IdentityFileinsecure_private_key

Without delving into the private keys, I suspected maybe some ports were being tied up, so I remapped the port forwards and I found limited success (ie it worked with the Ubuntu VM) by adding this line into my Vagrantfile :在不深入研究私钥的情况下,我怀疑可能某些端口被绑定了,所以我重新映射了端口转发,但通过将此行添加到我的Vagrantfile中,我发现成功有限(即它与 Ubuntu VM 一起工作):

config.vm.network:forwarded_port, guest: 22, host: 8765, id: 'ssh'

Where the host port was changed from the default 2222 to 8765 (just a random port allocation).主机端口从默认的2222更改为8765 (只是一个随机端口分配)。

When I ran a vagrant destroy and vagrant up this then brought up the Ubuntu VM and I was able to successfully vagrant ssh into the VM.当我运行vagrant destroyvagrant up它启动了 Ubuntu VM,我能够成功地vagrant ssh放入 VM。 I ran the vagrant destroy simply because I wanted to start the image afresh, not because I had any indication that I needed to.我运行vagrant destroy只是因为我想重新启动图像,而不是因为我有任何迹象表明我需要这样做。

However, when I ran this same approach with the CentOS VM, it still timed out, so I am delving into the reason for that.然而,当我对 CentOS VM 运行同样的方法时,它仍然超时,所以我正在研究其中的原因。


UPDATE:更新:

I have concluded that installing Docker Destkop for Windows caused a series of changes to my system that essentially broke VirtualBox with Vagrant .我得出的结论是, Docker Destkop for Windows导致我的系统发生一系列变化,这些变化基本上破坏了带有VagrantVirtualBox

I have the following steps as my minimum viable resolution :我有以下步骤作为我的最低可行解决方案

  1. Uninstall Docker Desktop Client卸载Docker Desktop Client
  2. Disable a series of Windows Features that are related to virtualization or containers禁用与虚拟化或容器相关的一系列 Windows 功能
  3. Check CPU-Z and Intel Processor Identification Utility to verify that VT-x is now enabled检查CPU-ZIntel Processor Identification Utility以验证VT-x现在已启用
  4. Run a vagrant reload on my VM in question在我有问题的 VM 上运行vagrant reload
  5. Uncheck cable connected and re-check cable connected取消选中已cable connected并重新检查已cable connected
  6. vagrant ssh now works. vagrant ssh现在可以使用了。

I will need to restore each feature one at a time to see how far I can go before breaking this again.我将需要一次恢复每个功能,看看在再次破坏之前我能 go 走多远。

Here's a screenshot of the various tidbits, and the pointers:这是各种花絮和指针的屏幕截图:

(1) Disabled Containers in Windows (2) Disabled Hyper-V (3) Disabled Virtual Machine Platform (4) Disabled Windows Hypervisor Platform (5) Disabled WSL (6) Now VT-x shows up again (it was not showing up previously) (7) Now SLAT shows up again (it was not showing up previously) (8) CPU-Z sees VT-x as well (1) 禁用容器 Windows (2) 禁用 Hyper-V (3) 禁用虚拟机平台 (4) 禁用 Windows Hypervisor 平台 (5) 禁用 WSL (6) 现在 VT-x 再次出现(之前没有出现) ) (7) 现在 SLAT 再次出现(之前没有出现) (8) CPU-Z 也看到 VT-x

在此处输入图像描述

I now also note that Enable Nested VT-x is no longer greyed out on my CPU settings menu in VirtualBox.我现在还注意到, Enable Nested VT-x在 VirtualBox 的 CPU 设置菜单上不再灰显。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM