下面是我的流浪者文件
# -*- mode: ruby -*-
# vi: set ft=ruby :
#Virtualbox host and vagrant host/network confs
#
Vagrant.configure("2") do |config|
config.vm.define "slave" do |slave|
slave.vm.box = "centos/7"
slave.vm.hostname = "slave.ansible.com"
slave.vm.network :private_network, ip: "192.168.99.102"
slave.ssh.insert_key = false
slave.vm.boot_timeout = 800
slave.ssh.private_key_path = ["keys/id_rsa_slave"]
slave.vm.provision "file", source: "keys/id_rsa_slave.pub", destination: "~/.ssh/authorized_keys"
end
config.vm.provider "virtualbox" do |vb|
vb.cpus = "1"
vb.memory = "512"
end
这个Vagrantfile位于我的主目录(/user/gokul/slave(下的slave文件夹中,在此之下,我有具有以下键和适当权限的密钥目录
(base) Gokul:slave gokul$ ls -lt keys/
total 16
-rw------- 1 gokul gokul 565 May 16 18:30 id_rsa_slave.pub
-rw------- 1 gokul gokul 2590 May 16 18:30 id_rsa_slave
密钥目录的权限也很好
(base) Gokul:slave gokul$ ls -ld keys/
drwx------ 4 gokul gokul 128 May 16 18:30 keys/
现在我运行以下命令来启动我的流浪箱
流浪起来
此时它挂起,无法进行身份验证
==> master: Waiting for machine to boot. This may take a few minutes...
master: SSH address: 127.0.0.1:2200
master: SSH username: vagrant
master: SSH auth method: private key
master: Warning: Authentication failure. Retrying...
master: Warning: Authentication failure. Retrying...
SSH authentication failed! This is typically caused by the public/private
keypair for the SSH user not being properly set on the guest VM. Please
verify that the guest VM is setup with the proper public key, and that
the private key path for Vagrant is setup properly as well.
启用调试后,我还可以看到它选择了我要求的私钥,但是,它无法成功进行身份验证并失败并出现上述错误。
想通了。我正在使用的自定义密钥应该附加到默认的 vagrant 密钥 - ~/.vagrant.d/insecure_private_key
所以这个配置
slave.ssh.private_key_path = ["keys/id_rsa_slave"]
应改为
slave.ssh.private_key_path = ["keys/id_rsa_slave", "~/.vagrant.d/insecure_private_key"]
进行此更改后,我运行了
流浪起来
它成功了。