简体   繁体   中英

Cannot ssh into newly created vagrant box

Just created a new vagrant box with minimal centos 7.

I followed this guide. https://blog.engineyard.com/2014/building-a-vagrant-box

Also I have everything in place as mentioned in official vagrant guides here and here

However when I try to do vagrant up. It timeouts when trying to ssh into the box.

What might be causing this? My network adapter in the VM is NAT. I tried to set private network ip

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

I was able to ssh using this ip and vagrant as username and password. I wonder why vagrant is not able to ssh? Here is the output of 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

And after a long time it gives this error.

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 keys set using the following commands

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

There was a bug in 1.8.5 that can explain this.

can you please upgrade to 1.8.6 ?

您是否尝试过使用

vagrant ssh

This might help someone. Try running ip addr command and if the network interface has no IP address assigned to it then you need to set ONBOOT to yes .

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

Then change ONBOOT=no to ONBOOT=yes Restart the machine and run ip addr to make sure that network is started properly and an IP address is assigned to the network interface.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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