VM provider I am using virtualbox, OS is centos7
Before you create your own virtualbox, on the need virtualbox we have built a virtual machine. As well as having been set up virtual machines, virtual machine named cusbox_vb1
Good use has been set up virtual machines can create your own vagrant box. We need to shut down the virtual machine before creating the box.
Create a vagrant box
box name vagrant names package --base --output virtual machines to be created , such as: vagrant package --base cusbox_vb1 --output cusbox
Directory where is located the newly created command execution vagrant box
The newly created file box below
Vagrant box add to the default directory
The default directory vagrant box is ~ / .vagrant.d / Boxes , where ~ is the user's home directory.
To create a virtual machine first need to create a good box to the default directory to use vagrant box
box name after adding vagrant box add the box to add the name of
vagrant box add cusbox ./cusbox
View all box default directory
After you add can go to the default directory (~ / .vagrant.d / boxes) to view the next, you can find cusbox folder has been added
You can also use vagrant box list command to see all box default directory
vagrant box list
Initialization vagrant environment to generate vagrantfile
Add the box to the default directory, ready to initialize, it will generate Vagrantfile file the following command
vagrant init box name
vagrant init cusbox
Start the virtual machine
vagrant up
At this time, although you can start a virtual machine, but can not be certified, the following conditions, it is because there is no configuration ssh keys
Configuring SSH keys
For the above reasons the default private host error authentication fails, resolve as follows:
1, the host performs the first private vagrant ssh-config view to modify the default path.
$ vagrant ssh-config Host default HostName 127.0.0.1 User vagrant Port 2221 UserKnownHostsFile /dev/null StrictHostKeyChecking no PasswordAuthentication no IdentityFile C:/myvagrant/mkbox/Borg-web/.vagrant/machines/default/virtualbox/private_key IdentitiesOnly yes LogLevel FATAL
IdentityFile is the path where the key
After vagrant up, will generate .vagrant directory, copy the existing private_key to the default path to .vagrant \ Machines \ default \ VirtualBox / private_key,
vagrant halt off and then restart the vagrant up, then you can start, and through vagrant ssh command to log in to the virtual machine.
The public key of the virtual machine is generally located /home/vagrant/.ssh directory authorized_keys file,
See below
[vagrant@localhost .ssh]$ cat authorized_keys ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDa/VjIVZGQaTrPC1+k805wOJ+KGoLmwdLURHKT1RhhbNfBl1NYgbsZdTHAoE+nX1ksaM4p0yzFhDXxbiIYgJhg7gHkDHQpqzYXjZwZi9kLokxgA+gNfCu4HzDBFoOj2V0DaMEYnWRgHfpTR4Gw5brrfObwtkWy6iuNCok4a/j0Gpj16kfidTwOjYmGsfS7pGfQ+P9e9XUysQ9909MpT7rA30jeNbNN0gYr2p6M50wpXjyZLiTyMN+r1wq+oH3zSQ6dPmWu3cqyQlX7554sJDDGpmE8K4uGFgHmh+1neCoe0UWku3eYUcZKp5FnkfvKPVNHuW4lzY7IwKHsjWQ7q92Z vagrant [vagrant@localhost .ssh]$
2. If there is no existing public and private keys, you can use the ssh-keygen command generates
ssh-keygen
It generates the following two files id_rsa and id_rsa.pub, is a former private key file, after a public key file, the contents of this private key file to override the default file host of problems can be solved certification.
Because before certification can not get logged by vagrant ssh, so through the virtual box itself client login functionality , user name and password are vagrant, after login you can use ssh-keygen to generate a public key and a private key
Log on to the virtual machine
vagrant ssh