vagrant 自定义 ssh 密钥身份验证失败
vagrant custom ssh key authentication failure
下面是我的 Vagrantfile
# -*- 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
keys目录权限也可以
(base) Gokul:slave gokul$ ls -ld keys/
drwx------ 4 gokul gokul 128 May 16 18:30 keys/
现在我 运行 下面的命令来启动我的 vagrant box
vagrant up
此时挂起,无法验证
==> 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.
启用调试后,我还可以看到它获取了我要求的私钥,但是,它无法成功验证并因上述错误而失败。
想通了。我使用的自定义键应该附加到默认的 vag运行t 键 - ~/.vag运行t.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"]
进行此更改后,我 运行
vagrant up
并且上线成功
下面是我的 Vagrantfile
# -*- 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
keys目录权限也可以
(base) Gokul:slave gokul$ ls -ld keys/
drwx------ 4 gokul gokul 128 May 16 18:30 keys/
现在我 运行 下面的命令来启动我的 vagrant box
vagrant up
此时挂起,无法验证
==> 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.
启用调试后,我还可以看到它获取了我要求的私钥,但是,它无法成功验证并因上述错误而失败。
想通了。我使用的自定义键应该附加到默认的 vag运行t 键 - ~/.vag运行t.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"]
进行此更改后,我 运行
vagrant up
并且上线成功