【问题标题】:Vagrant SSH connection failureVagrant SSH 连接失败
【发布时间】:2017-03-21 16:32:21
【问题描述】:

我有一个 Ubuntu 16.04 LTS 和三个 Vagrant/VirtualBox 虚拟机需要同时打开

当我用 VirtualBox 安装 Vagrant 时,第一天,SSH 连接正常。第二天我在三台机器上得到了这个(这里是其中一台的例子):

xxxx-callserver@xxxxcallserver-Precision-WorkStation-T5400:~/VM$ vagrant up vvs --provision
Bringing machine 'vvs' up with 'virtualbox' provider...
==> vvs: Checking if box 'dmservices/fedora17-x86_64' is up to date...
==> vvs: Clearing any previously set forwarded ports...
==> vvs: Clearing any previously set network interfaces...
==> vvs: Preparing network interfaces based on configuration...
    vvs: Adapter 1: nat
    vvs: Adapter 2: hostonly
==> vvs: Forwarding ports...
    vvs: 22 (guest) => 2222 (host) (adapter 1)
==> vvs: Running 'pre-boot' VM customizations...
==> vvs: Booting VM...
==> vvs: Waiting for machine to boot. This may take a few minutes...
    vvs: SSH address: 127.0.0.1:2222
    vvs: SSH username: vagrant
    vvs: SSH auth method: password
    vvs: Warning: Remote connection disconnect. Retrying...
    vvs: Warning: Authentication failure. Retrying...

直到它触发超时

当我尝试vagrant ssh vvs 时,有或没有--plain:

==> vvs: The machine you're attempting to SSH into is configured to use
==> vvs: password-based authentication. Vagrant can't script entering the
==> vvs: password for you. If you're prompted for a password, please enter
==> vvs: the same password you have configured in the Vagrantfile.
Permission denied (publickey).

这是那台机器的 Vagrantfile 部分(三台机器之间的唯一区别是名称、ip(在同一网络 192.168.33.0/24 内),另外两台是 debian/jessie64):

Vagrant.configure("2") do |config|
    ...
    ...
    config.vm.define "vvs" do |vvs|
        vvs.vm.hostname = "vvs"
        vvs.vm.box = "dmservices/fedora17-x86_64"
        vvs.vm.network "private_network", ip: "192.168.33.4"
        vvs.ssh.username = "vagrant"
        vvs.ssh.password = "vagrant"
        vvs.vm.synced_folder "/home/xxxx-callserver/NetBeansProjects", "/NetBeansProjects", create: true, type: "virtualbox"  
        vvs.vm.provider "virtualbox" do |v|
            v.memory = 2048
            v.cpus = 2
            v.customize ["modifyvm", :id, "--vram", "64"]
    end
end

提前致谢,如果需要,请向我询问更多信息

编辑: vagrant ssh-config 的输出

Host avaya
  HostName 127.0.0.1
  User vagrant
  Port 2201
  UserKnownHostsFile /dev/null
  StrictHostKeyChecking no
  PasswordAuthentication no
  IdentityFile /home/xxxx-callserver/VM/.vagrant/machines/avaya/virtualbox/private_key
  IdentitiesOnly yes
  LogLevel FATAL

Host videogateway
  HostName 127.0.0.1
  User vagrant
  Port 2200
  UserKnownHostsFile /dev/null
  StrictHostKeyChecking no
  PasswordAuthentication no
  IdentityFile /home/xxxx-callserver/VM/.vagrant/machines/videogateway/virtualbox/private_key
  IdentitiesOnly yes
  LogLevel FATAL

Host vvs
  HostName 127.0.0.1
  User vagrant
  Port 2222
  UserKnownHostsFile /dev/null
  StrictHostKeyChecking no
  PasswordAuthentication no
  IdentitiesOnly yes
  LogLevel FATAL

【问题讨论】:

  • 您是否可以使用 ssh 直接访问该 IP(使用相同的凭据?您是否可以通过 Virtualbox GUI 使用这些凭据登录?vagrant ssh-config 的输出是什么?
  • @GonzaloMatheu 编辑了 ssh 配置。是的,我可以像使用普通的 VirtualBox 一样访问操作系统
  • 您可以使用 ssh ssh -p 2222 UserKnownHostsFile=/dev/null vagrant@127.0.0.1 或 ssh -p 2200 UserKnownHostsFile=/dev/null -i /home/xxxx-callserver/VM/.vagrant/machines/videogateway/virtualbox/private_key vagrant@127.0.0.1 进行连接吗?
  • 你是把 3 台 vagrant VM 放在同一台电脑还是 3 台不同的电脑上?
  • @GonzaloMatheu 给出以下错误ssh: Could not resolve hostname userknownhostsfile=/dev/null: Name or service not known

标签: ssh vagrant virtualbox


【解决方案1】:

请检查您是否将每个 Vagrant 访客端口 22 显式转发到不同的主机端口。我不熟悉 vagrant 脚本,但您确实需要一行来明确指定不同的端口,因为默认 Vagrant 总是将 22 映射到 2222。对于多个 VM。这意味着只有第一个 vagrant VM 将其映射正确,其余的将失败。在 Vagrantfile 中,您需要为每台客户机提供类似的东西。

# avaya
config.vm.network :forwarded_port, id: 'ssh', guest:22, host: 2201, 

# videogateway
config.vm.network :forwarded_port, id: 'ssh', guest:22, host: 2200, 

# vvs
config.vm.network :forwarded_port, id: 'ssh', guest:22, host: 2222,

由于您已经将第一个虚拟机设置为从 22 到 2222 的端口转发,因此所有 3 个虚拟机都将无法更改端口转发映射。或许你应该考虑将主机vvs转发到不同的主机端口,这样就不会与未来使用默认电源转发的adhoc vagrant启动冲突。

【讨论】:

  • 我只在 Vagrantfile 中用vvs.vm.network "forwarded_port", id: "ssh", guest: 22, host: 2201 开启了一个虚拟机 (vvs)(videogateway 有 2202,avaya 有 2200),它会继续循环到 vvs: Warning: Authentication failure. Retrying... 直到超时
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-11-25
  • 2016-09-09
  • 1970-01-01
  • 1970-01-01
  • 2014-05-20
  • 2017-01-06
  • 1970-01-01
相关资源
最近更新 更多