流浪的SSH连接失败

时间:2017-03-17 12:38:18

标签: ssh vagrant virtualbox

我有一个需要同时打开的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

1 个答案:

答案 0 :(得分:0)

请检查您是否明确将每个Vagrant访客端口22转发到不同的主机端口。我不熟悉vagrant脚本,但你确实需要一行来明确指定不同的端口,因为默认的Vagrant总是映射22到2222.对于多个VM。这意味着只有第一个流浪汉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,

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