【问题标题】:Cannot ssh into newly created vagrant box无法通过 ssh 进入新创建的 vagrant box
【发布时间】:2017-05-26 01:45:47
【问题描述】:

刚刚用最少的 centos 7 创建了一个新的 vagrant box。

我遵循了本指南。 https://blog.engineyard.com/2014/building-a-vagrant-box

此外,正如官方流浪指南 herehere 中提到的那样,我已经准备好了一切

但是,当我尝试做 vagrant up 时。尝试 ssh 进入盒子时超时。

这可能是什么原因造成的? 我在虚拟机中的网络适配器是 NAT。 我尝试设置私网ip

config.vm.network "private_network", ip: "192.168.50.4"

我能够使用这个 ip 和 vagrant 作为用户名和密码进行 ssh。我想知道为什么 vagrant 不能 ssh? 这是vagrant up的输出

Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'my'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: my_box_default_1475351710988_24744
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key

过了很长一段时间它给出了这个错误。

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.

使用以下命令设置 ssh 密钥

mkdir -p /home/vagrant/.ssh
chmod 0700 /home/vagrant/.ssh
wget --no-check-certificate https://raw.github.com/mitchellh/vagrant/master/keys/vagrant.pub -O /home/vagrant/.ssh/authorized_keys
chmod 0600 /home/vagrant/.ssh/authorized_keys
chown -R vagrant:vagrant /home/vagrant/.ssh

【问题讨论】:

    标签: ssh vagrant virtualbox


    【解决方案1】:

    1.8.5 中有一个错误可以解释这一点。

    你能升级到 1.8.6 吗?

    【讨论】:

    • 我升级到 1.8.6。重建盒子。但同样的问题。
    • 可以分享一下你在添加authorized_keys后创建vagrant用户并设置ssh目录权限的脚本吗?
    • 我在问题中添加了命令。只是为了让你知道我也尝试使用 ssh 的密码。
    【解决方案2】:

    您是否尝试过使用

    vagrant ssh
    

    【讨论】:

      【解决方案3】:

      这可能对某人有所帮助。 尝试运行ip addr 命令,如果网络接口没有分配IP 地址,则需要将ONBOOT 设置为yes

      [root@localhost ~]# vi /etc/sysconfig/network-scripts/ifcfg-enp0s3
      

      然后将ONBOOT=no改为ONBOOT=yes 重启机器并运行ip addr,确保网络正常启动并为网络接口分配了IP地址。

      【讨论】:

        猜你喜欢
        • 2013-11-21
        • 1970-01-01
        • 2016-04-09
        • 2021-07-09
        • 2014-09-13
        • 2014-05-03
        • 2013-06-20
        • 2012-07-24
        • 1970-01-01
        相关资源
        最近更新 更多